Inheritance Flashcards
How many superclasses can be specified for a subclass?
One
Can a subclass access private members of its superclass?
No. inheritance doesn’t overrule private access restriction.
Accessor methods
Provide access to private members of a class
Which constructor creates an object given class inheritance?
The superclass constructor creates the superclass portion of the object & the subclass constructor creates the subclass portion.
The superclass portion of the object is constructed automatically using its default constructor.
How can a subclass call a constructor defined by its superclass?
super()
In a multilevel hierarchy, which constructor will superclass refer to?
The constructor in the closest superclass
How can you access superclass methods?
Super()
When are constructors executed in a class hierarchy?
Constructors execute in order of derivation from superclass to subclass
Can a reference variable of a superclass be assigned a reference to an object of a subclass?
Yes
Reference variable
Used to refer to an object
Can reference variables refer to objects of different class types?
No
What members do you have access to with a superclass reference variable?
The parts of the object defined by the superclass
How do you construct a copy of an object?
Define a constructor that takes an object of the class as its parameter
Method Overriding
When a method in a subclass has the same return type and signature as a method in its superclass.
When you call an overridden method in a subclass, which method is returned?
It will always refer to the subclass method