tririd
TRIRID
Computer Coaching Institute
Facebook Google Plus Tweeter

BLOG

INHERITANCE

What is Inheritance

Its mechanism of building new class from existing class.

why Inheritance is used in programming?

Inheritance is used to reuse code of existing/old class in new class.In this way we can increase time and space efficiency.
Existing/Old class is called parent class,New class is called child class.
Existing class<---------------------------------->Parent/Super/Base class

New class<--------------------------------------->Child/Sub/Derived class
Here, no. of parent class and child class can vary,according to this no. of class there are types of inheritance.

Types of Inheritance

Single Inheritance
One parent class and one child class
A------------------------>B
Multilevel Inheritance
One parent class and one child class,again new class derived from that child class
A------------------>B------------------->C
Multiple Inheritance
More than one parent class and one child class
A------------------>C,
B------------------->C
Hierarchical Inheritance
Parent class inherited to more than one child class
A------------------>B,A------------------->C

Derived class can do following :

Based on this also there are two types of Inheritance.
1)Augmenting Inheritance:
Here child class add a new method ,which wasn't present in parent class,its augmenting.
i.e.
Television<------------------------------>Base Class
Delux Tv <------------------------------->Sub Class
Here,Television is base class, and Delux tv is derived from TV. So, Delux tv has those channels, which contains Television, and also we can add other new channels also.These new channels are not present in Television.Its Augmenting Inheritance.
2)Specialized Inheritance:
Here, child class modifies/overriding superclass's methods,its specialized. i.e.Some functions of windows 7 are changed in windows 8.So, functionality is same in both base and derived class. But some feachures are modified in child class.