Class design Flashcards
Inheritance
Inheritance is the process by which the new child subclass automatically includes any public or protected primitives, objects, or methods defned in the parent class.
Java supports single inheritance, by which a class may inherit from only one direct parent class.
Java doesn’t support multiple inheritance!
Java allows only one public class per file
true
public access modifer
The public access modifer applied to a class indicates that it can be referenced and used in any class.
default package private modifer
The default package private modifer, which is the lack of any access modifer, indicates the class can be accessed only by a subclass or class within the same package.
java.lang.Object
java.lang.Object is the only class that doesn’t have any parent classes.
The first statement of every constructor is a call to another constructor within the class using this(), or a call to a constructor in the direct parent class using super().
true
The super() call may not be used after the first statement of the constructor.
true
If no super() call is declared in a constructor, Java will insert a no-argument super()
as the first statement of the constructor.
true
If the parent doesn’t have a no-argument constructor and the child doesn’t define any constructors, the compiler will throw an error and try to insert a default no-argument constructor into the child class.
true
If the parent doesn’t have a no-argument constructor, the compiler requires an explicit
call to a parent constructor in each child constructor
true
Hiding Static Methods
A hidden method occurs when a child class defnes a static method with the same name and signature as a static method defned in a parent class.
Overriding vs. Hiding Methods
Unlike overriding a method, in which a child method
replaces the parent method in calls defned in both the parent and child, hidden methods only replace parent methods in the calls defned in the child class.
final methods cannot be overridden.
true
Hiding Variables
When you hide a variable, you defne a variable with the same name as a variable in a parent class.
This creates two copies of the variable within an instance of the child class: one instance defned for the parent reference and another defned for the child reference.