Java Inheritance (IS-A)

When a class is derived from a base class, the derived class inherits all the characteristics of base class and can add new features as refinements and improvements. This is called inheritance.

Inheritance represents the IS-A relationship, also known as parent-child relationship.

The following figure shows the inheritance.

inheritance introduction

Figure: relation between base and derived class

Inheritance doesn’t work in reverse order i.e. features in derived class can not be accessed by the base class object.

The following figure depicts the implemented version of base and derived class relationship.

inheritance-example

Figure: Class car derived from vehicle

 

Java Nested Classes