Wednesday, October 17, 2007

Java Enum and Its Superclass

All java enum implicitly extend from java.lang.Enum. Since java doesn't allow multiple inheritance, enum types can't have superclass. They can't even extend from java.lang.Enum, nor java.lang.Object. It also means enum A can't inherit or extend enum B.

For example, the following is an invalid enum declaration:

public enum MyNumENUM extends Object {

Compiler error: '{' expectedpublic enum MyNumENUM extends Object { expected
2 errors

The correct form should be:

public enum MyNumENUM {

No comments:

Post a Comment