Inheritance is a mechanism in which one object aquarius all the properties and behaviour of parent class to child class.
Advantages: code reusability and extensibility
While heritance all the members of a class me will be inherited in to subclass except private members and constructors.
Types of inheritance:
There are 4 types of inheritance is given below
1. Single inheritance.
2. Multiple inheritance.
3. Multilevel inheritance.
4. Hierarchial inheritance.
Multiple inheritance is not supported java.
Calling to a super class methods or variables it is possible only by a word "super".
Advantages:
- Reduce code redundancy
- Provides code reusability
- Reduces source code sizes and improves code reusability
- Code is easy to manage divided into parent and child class
- Supports Code exntendability by overriding the base class functionality with in child class
Disadvantages:
- In Inheritance base class and child class are tightly coupled.Hence if you change the code of parent class it will get affected to the all the child classes.
- In class hierarchy many data numbers remain unused andathe memory allocated to them is not utilised. Hense effect performance of your program if you have not implemented inheritance correctly.
No comments:
Post a Comment