Inheritance Flashcards
The process of creating derived classes from a base class to enhance code reusability.
Inheritance
Inheritance relationship can be described as
superclass-subclass
is-a/an, is-a-kind-of
has-a
the “is-a” rule states that __________ of the subclass is an object of the superclass
every object
You can use a subclass object whenever the program expects a superclass.
Substitution Principle
What features can be inherited by the subclass?
Public and Protected
The super constructor must always be the ____________ in another constructor.
first statement
The collection of classes extending from a common superclass is called an ________________________
Inheritance Hierarchy
The path from a particular class to its ancestor is its ______________________.
Inheritance chain
When some methods in superclass is not appropriate for the subclasses, the solution is to _________________________
override methods
When designing Classes, place the _______________ in the superclass
general methods
Place the more ______________ in the subclass(es)
specialized methods
Subclasses are more superior because they have more functionality than superclasses
TRUE
Benefits of Inheritance
- Forms ranking or ordering of abstractions
- Simplifies our understanding of a problem
- Allows code reuse
Java employs _______ inheritance
Single
top of hierarchy
java.lang.Object
All classes in the Java Platform are descendants of the _____________
Object class
user within the subclass to refer to its superclass, or to invoke constructor, method or attribute (discouraged) of the super class.
Super keyword
constructors are not inherited.
TRUE
Redeclaring and redefining a method of the superclass in the subclass
Method Overriding
In overriding a method, the _____ and _________ (name, parameter types) should be the same as the original method
return type, method signature
When overriding a method, the access modifier should be the same or less strict.
TRUE
Given the method:
int add (int x, int y);
is the method overriding:
protected int add (int a, int b);
valid?
YES, from default to a less strict access modifier (protected)
With ___________ keyword, there is no need to implement the method (no method body required)
Abstract
For added clarity, a class with one or more abstract methods must itself be declared abstract
TRUE