2. Advanced class design Flashcards
What is the natural sorting order of enums?
The natural order of enums is the order in which they are defined
Are anonymous classes final?
Anonymous classes are implicitly final
Can an anonymous class be static?
Anonymous classes can NEVER be static!
How can a static method of an interface be accessed?
An static method of an interface can only be accessed by using the name of that interface
Wich acces modifier does a enum constructor have?
Enum constructors are always private. If an enum type has no constructor declaration, then a private non-arg constructor is automatically provided
Is an enum final?
An enum is implicitly final
With two methods does the compiler provides an enum?
public static values() and public static valueOf(String)
What does values() return?
values() returns an array of it constants
what does Enum.valueOf(String) return?
valueOf(String) tries to match the string argument exactly with an enum constant. returns constant if successful else illegalArgumentException
can an enum be defined inside any class?
A public (or non-public) enum can be defined inside any class
Can an enum be defined as static?
An enum can be defined as a static member of any class. You can also have multiple public static enums inside the same class
Can an enum be defined inside a method or constructor?
An enum cannot be defined inside any method or constructor
What does the enum method ordinal() do?
Enums have a method ordinal(), with returns the index starting with 0
What does the enum method name() do?
Enums have a method name(), with returns the name of this enum constants
Can you acces a non-final static field from an enums constructor?
You cannot access a non-final static field from an enums constructor