2. INHERITANCE
OOP allows class to create new classes which
may have some common feature to the exiting
classes this is achieved by inheritance.
Inheritance is a process of creating new class
from the existing class.
The existing classes are called base class or
super class and the inherited classes are
called derived classes or sub class
3. Types of inheritance
1. Single inheritance
2. Multiple inheritance
3. multi-level inheritance
4. Single inheritance
In this case there is only 1 base and derived class and
inheritance take place between them. For ex:Class animal
{
Bones
Legs
hand
}
Class vertebrates
{
Bones
Legs
}
5. Multiple inheritance
If the child class interact from more than one parent class the it is called multiple inheritance.
Class aquatic animals
{
Breath in water
Gills
}
Class land animals
{
Breath in air
Lungs
}
Class amphibian
{
Breath in water
Breath in air
Lungs
Water
}
6. Multi-level inheritance
When a sub class is derived from a class which is derived from some other class then it is called multi –
level inheritance.
class transport
{
Fly
Sail
}
Class water transport
{
Sail
No of passenger
}
Class boats
{
sail
No of passenger
}