Inheritance:
- It is a process where one class acquires the properties (methods and attributes) of another.
- class which inherits the properties of other is known as subclass (derived class, child class)
- class whose properties are inherited is known as superclass (base class, parent class).
Ref:https://www.tutorialspoint.com/java/java_inheritance.htm
Why we need inheritance??
Code Reusability:
- The basic need of an inheritance is to reuse the features.
- Like we defined once we can use it later whenever we need that in any class.
Extensibility:
- The inheritance helps to extend the functionalities of a class.
- If you have a base class with some functionalities, you can extend them by using the inheritance in the derived class.
Better Code Organization:
- Helps in structuring and organizing code effectively.
- By creating a hierarchy class, you can group related functionalities, making the code more modular and easier to maintain.
Consistency Across Classes:
- Changes made in the parent class are automatically reflected in all its child classes.
Top comments (0)