Java Reference
In-Depth Information
Summary
Inheritance is the most important feature of object-oriented program-
ming. It allows a new class to be written that extends an existing class.
This new class inherits all of the attributes and behaviors of its parent.
■■
The is a relationship is a simple but important step used to determine if
inheritance is a good design. You should be able to say “A child object is
a parent object.”
■■
The extends keyword is used to implement inheritance. A class in Java
can only extend one class.
■■
If a class does not explicitly extend another class, then its parent class is
java.lang.Object. The Object class is at the top of the entire Java hierarchy,
and it contains useful methods that can be invoked on any object, such
as toString(), equals(), and hashcode().
■■
Method overriding is when a child class contains the same method as
its parent class.
■■
The super keyword is used by a child class to explicitly access a field in
the parent class or explicitly invoke a method in the parent class.
■■
A final class cannot be extended. A final method cannot be overridden.
■■
A child class can invoke a constructor in its parent using the super()
syntax, which must be the first statement in a constructor. If a construc-
tor does not explicitly invoke super() or this(), then the compiler adds a
call to super() (with no arguments) to the constructor.
■■
Search WWH ::




Custom Search