What
is Inheritance?
A
systematic approach to programming where in a new class is created by absorbing
an existing class state and behavior, and extending it with new, more specific
behavior. Inheritance is a compile-time mechanism in Java that allows you to
extend a class (called the base class
or superclass) with another class
(called the derived class or subclass).
It
allows new object definitions in terms of existing ones. In mathematical format,
the inheritance can be written as:
R = X + ~ X
R: newly defined class
X: Set of properties inherited from an existing
object class
~X: new properties
When
a Java class is defined it can be defined as an extension of another class using
the keyword extend. For example, the following class definition declares that
class B extends the definition of class A.
public
class B extends A {
// instance and class member definitions