
by
PRO
FE S
S OR

I N H E R I T A N C E
AN OBJECT-ORIENTED PILLAR
In Object-Oriented Language, INHERITANCE refers to the fact that:
To understand this, let's have an example:
By Inheritance the Automobile class and the Truck class both can use, access and invoked all attributes and methods of the Vehicle class as if they were their own, without having to define them.
Ideally, Inheritance should follow the "is a" relationship.
The "is a" relationship is followed.
Why INHERITANCE:
In JAVA code the 'extends' operator allows a class to inherit from another class.
See below JAVA code example of Inheritance, using a parent class Vehicle and a child class Automobile.
class Vehicle
{
private double velocity;
void speed(double tmpTime)
{
class Automobile extends Vehicle
{
// The Automobile class can use the attributes "mileage" and "velocity" and
the method "speed" of the Vehicle class as its own.