Inheritance in Object Oriented Programming Model OOP

Inheritance is the process of acquiring the properties of the base class into the sub class. The inheritance concept is very useful for reusability.

Inheritance with Example

For example: Car is a sub class of FourWheeler class. Here Car acquires the properties of the FourWheeler class. Other sub classes could be a Jeep, Tempo, Van etc. FourWheeler class defines vehicles that have four wheels, and specific range of engine power, load carrying capacity etc. Car acquires these properties from FourWheeler, and has some specific properties, which are different from other classifications of Four Wheeler, such as luxury, comfort, shape, size, usage etc.

A Car class can have further sub classes such as an OpenCar, Hatchback, Sedan, SUV, etc, which will acquire the properties from both Four Wheeler and Car, but will still have some specific properties. This way the level of hierarchy can be extended to any level.

In java above can be implemented like this:
  
class FourWheeler
{
public static final int noOfWheels= 4; //constant
String color;
}
class Car extends FourWheeler
{
//here both the properties 
of the FourWheeler are directly 
available here
System.out.println(“Number of wheels of the car are”+noOfWheels);
// acquired / accessing the parent 
class property noOfWheels
}