• Post Reply Bookmark Topic Watch Topic
  • New Topic

override in enum  RSS feed

 
mahboob ali khan
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please explain with a simple code, how to override a method in enum???
 
Chan Ag
Rancher
Posts: 1090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

how to override a method in enum???


Try extending an enum first? Let us know how it went? Yeah?

Chan.

Edit : Ignore this response, please.
 
Wilhelm Vogt
Greenhorn
Posts: 10
Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might look at the end of Chapter 8 in the JLS, Example 8.9.2-4. Enum Constants with Class Bodies, or this thread from Programmer Certification: enums. The syntax for the overriding method is standard, but as enums are special classes, the enclosing class looks different than an ordinary class definition - feel free to ask again, as the JLS is not easy to read.
 
Chan Ag
Rancher
Posts: 1090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Doesn't overriding happen when we already have a method definition somewhere in the hierarchy and still we provide a new definition? When a subclass defines an abstract method, it is still not overriding so long as there is no other definition already available somewhere in the hierarchy. Or is it?

Do enums allow us to redefine a properly defined method?
 
Chan Ag
Rancher
Posts: 1090
14
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just checked. Enums allow us to override already defined methods.



The above code compiled. I stand corrected. Thanks, Wilhelm Vogt.

Chan.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!