Inheritance In Java At TCCI, Ahmedabad
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.
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
A------------------------>B
Multilevel Inheritance
One parent class and one child
class,again new class derived from that child class
A------------------>B------------------->C
A------------------>B------------------->C
Multiple Inheritance
More than one parent class and one
child class
A------------------>C,
B------------------->C
A------------------>C,
B------------------->C
Hierarchical Inheritance
Parent class inherited to more than
one child class
A------------------>B,A------------------->C
A------------------>B,A------------------->C
Derived class can do following :
- Inherite all members of base class expect its constructor.
- Access all public & protected members of the base class
- Define its own private member
- Define its own public member function
- Override function inheritted from the base class
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.
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 super class’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 features are modified in child class.
For More Information about Inheritance in java
at TCCI, Ahmedabad, computer
coaching institute, java
course
No comments:
Post a Comment