Key Concepts of OOPs
There are 4 main concepts (also called components or pillars) of Object-Oriented Programming:
Inheritance
Inheritance is a core feature of OOP where a class can acquire properties and behaviors from another class.
It allows the creation of new classes based on existing ones, promoting code reuse and specialization.
When inheritance occurs:
- A new class, known as the derived class or child class, is formed.
- It inherits from an existing class called the base class or parent class.
The derived class:
- Inherits all properties of the base class.
- Can introduce additional features or override existing ones.
- Does not affect the base class when changes are made.
Subclass / Derived Class: The class that inherits.
Superclass / Base Class: The class that is inherited from.
Types of Inheritance
● Single Inheritance
A class inherits from only one parent class, forming a simple hierarchical relationship.
The subclass extends and specializes functionalities of the superclass.
● Multiple Inheritance
A class inherits from more than one parent class, combining features from all.
Not supported directly in Java.
● Multilevel Inheritance
A class inherits from another class, and then another class inherits from that derived class.
This forms a chain of inheritance.
● Hierarchical Inheritance
Multiple classes inherit from a single base class.
● Hybrid Inheritance
inheritance mechanism that blends together the features of simple inheritance, multiple inheritance, and hierarchical inheritance.