inheritance, which is a form of software reuse in
which a new class is created by absorbing an existing class’s members and embellishing
them with new or modified capabilities. With inheritance, you can save time during program
development by basing new classes on existing proven and debugged high-quality
software. This also increases the likelihood that a system will be implemented and maintained
effectively.
When creating a class, rather than declaring completely new members, you can designate
that the new class should inherit the members of an existing class. The existing class
is called the superclass, and the newclass is the subclass. (The C++ programming language
refers to the superclass as the base class and the subclass as the derived class.) Each subclass
can become a superclass for future subclasses.
A subclass can add its own fields and methods. Therefore, a subclass is more specific
than its superclass and represents a more specialized group of objects. The subclass exhibits
the behaviors of its superclass and can modify those behaviors so that they operate appropriately
for the subclass. This is why inheritance is sometimes referred to as specialization.
The direct superclass is the superclass from which the subclass explicitly inherits. An
indirect superclass is any class above the direct superclass in the class hierarchy, which
defines the inheritance relationships between classes. In Java, the class hierarchy begins with
class Object (in package java.lang), which every class in Java directly or indirectly extends
(or “inherits from”).