aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Difference between inner class and inner enum Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Difference between inner class and inner enum" Watch "Difference between inner class and inner enum" New topic
Author

Difference between inner class and inner enum

Andry Dub
Ranch Hand

Joined: Nov 06, 2007
Posts: 43
public class MyClass {

abstract class A{} <- legal

abstract enum MyEn{MY,YOUR} <- illegal

final class B{} <- legal

final enum MyEn2{OUR,THEIR} <- illegal
}

Why inner class can be marked as abstract or final, but innec enum can't?


Java is my love
Kelvin Chenhao Lim
Ranch Hand

Joined: Oct 20, 2007
Posts: 513
It doesn't make sense to declare an enum as abstract, since there will always be at least one concrete instance of the enum. For example, "abstract enum MyEn { MY, YOUR }" says that there exist two MyEn instances (MY and YOUR), whereas the abstract modifier claims that there cannot be any MyEn instances. This is a logical contradiction, and so Java defines this as a compile-time error.

Also, you cannot extend an enum type, so all enums are in some sense already final. However, they're not really final in the usual sense, because each enum constant can have a class body that overrides the members of the enum type. Because enums have this special "final yet not quite final" quality, Java deems it a compile-time error to use the "final" modifier with enums.

Hope this helps!


SCJP 5.0
Andry Dub
Ranch Hand

Joined: Nov 06, 2007
Posts: 43
Thank you, Kelvin!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Difference between inner class and inner enum