Advanced Class Design Flashcards
Which keyword must be used in a class declaration if any of its methods uses the abstract keyword?
abstract
How do the contents of an abstract class differ from those of an interface?
An abstract class can contain implementation, while an interface cannot.
Which name must an anonymous class reference to implement an interface or extend a class?
The name of the interface or class that the anonymous class implements or extends.
Which method does the Enum class provide to retrieve an ordinal value for an enumeration constant?
ordinal
Which restriction limits objects when using an abstract class?
An abstract class cannot be instantiated.
Which restriction limits implementation when using a final class?
A final class cannot be extended.
Which keyword is used to implement members of an interface?
implements
Which method does the Enum class provide to iterate through enumeration constants?
values
How do the contents of an abstract class differ from a concrete class?
An abstract class can contain abstract members, while a concrete class cannot.
Which three modifiers are implicit for fields declared in an interface?
public static final
Which keyword is used to implement abstract members of an abstract class?
extends
Which keyword is used to inherit members from one interface to another interface?
extends
Can a static field override a non-static field in a superclass?
Yes. If the class declares a field with a certain name, then the declaration of that field is said to hide any and all accessible declarations of fields with the same name in superclasses, and superinterfaces of the class.
A hidden field can be accessed by using a qualified name if it is static, or by using a field access expression that contains the keyword super or a cast to a superclass type.
Can a static method override a non-static method in a superclass?
No! Java only allows:
- Overriding an instance method by an instance method and
- Hiding a static method by a static method
Can the abstract modifier be placed before the access modifier public as in: abstract public class TestClass { }
yes