Chapter 5: Class Design Flashcards
How can Java support multiple inheritance?
Through the use of interfaces
Does Java support multiple levels of inheritance?
Yes
How can you prevent a class from being extended?
By using the ‘final’ keyword
When extending a class without a no-argument constructor, what do you need to do?
Explicitly call super() with valid arguments for one of the super class’s constructors
T or F. You can execute code in the constructor before calling super()
False
Which is executed first? Parent or child constructor?
Parent
How can you access parent members?
Both ‘this’ and ‘super’ will work for inherited members
What are the requirements for overriding?
Must have the same signature
Child must be at least as accessible as the parent
Child may not throw a checked exception that is new or broader than one thrown by parent method
Return type must be same or subtype of parent return type
T or F. A subclass can have a method with the same name as a private method in the parent class
True
How can you explicitly call the parent’s version of an overridden method?
Using the ‘super’ keyword
What is a hidden static method?
A static method that has been overridden. Both must be static
Which version of a method is called if an overridden method is called on a child object in the parent class?
The child version
Which version of a method is called if a hidden method is called on a child object in the parent class?
The parent version
How do you prevent a static method from being hidden?
Make it ‘final’
What are the rules for defining an abstract method?
No implementation is provided in the class where it’s declared
It cannot be final
It can only be defined in an abstract class or interface
It cannot be private