У нас вы можете посмотреть бесплатно Enum Override: Constant-Specific Class Body Example или скачать в максимальном доступном качестве, видео которое было загружено на ютуб. Для загрузки выберите вариант из формы ниже:
Если кнопки скачивания не
загрузились
НАЖМИТЕ ЗДЕСЬ или обновите страницу
Если возникают проблемы со скачиванием видео, пожалуйста напишите в поддержку по адресу внизу
страницы.
Спасибо за использование сервиса ClipSaver.ru
Transcript: Enum allows each constant to override getMessage method So we can override getMessage method for Saturday and Sunday and return weekend from the overriding method Syntax is very easy but bit tricky Add a opening curly bracket after Saturday Press Enter Eclipse provides closing curly bracket That's it Just override getMessage method within these curly brackets Let me copy this getMessage method Paste it And we get green triangle We can use at the rate override annotation as well So this method overwrites getMessage method of parent Now who is parent over here Parent is enum day When an enum constant overwrites an enum method the enum constant creates an anonymous class which extends the enum We can verify this by visiting bin folder of this project Let me first save this file Open the bin folder We have day.class for this day.java and test day.3 class for testdaythree.java And we also have an extra file day dollar one dot class generated in the bin folder Let's go back to Eclipse This is known as constant specific class body An enum constant uses it to override methods or define new variables and methods Change the return statement to return weekend do the same thing for sunday as well add constant specific class body Copy getMessage declaration Paste it Now Sunday also overwrites getMessage method Save the file This also creates an anonymous class which extends enumday Check the bin folder And we have second class file day dollar 2 dot class generated in the bin folder Go to testdaythree.java and run this program and this time overriding method printed weekend for Saturday and Sunday If you are not allowed to modify enum code then you will have to go with solution one