The four principles of object-oriented programming
- The four pillars of object-oriented programming
- The four principles of object-oriented programming
- The 4 basics of object-oriented programming
- The building blocks of object-oriented programming
The four pillars or the four principles or the 4 basics or the building blocks of object-oriented programming are:
1. Abstraction
2. Encapsulation
3. Inheritance
4. Polymorphism
1. Abstraction
Hiding internal details and showing functionality is known as abstraction.
Examples:
(a) Phone call, we don’t know the internal processing.
(b) Consider a real-life example of a man driving a car. The man only knows that pressing the accelerators will increase the car speed or applying brakes will stop the car, but he does not know how on pressing the accelerator, the speed is actually increasing. He does not know about the inner mechanism of the car or the implementation of the accelerators, brakes etc. in the car. This is what abstraction is.
2. Encapsulation
The definition of encapsulation is “the action of enclosing something in or as if in a capsule”.
The meaning of Encapsulation, is to make sure that “sensitive” data is hidden from users. Encapsulation can be achieves by:
- declare class variables/attributes as private
- provide public get and set methods to access and update the value of a private variable
When one object acquires all the properties and behaviors of a parent object, it is known as inheritance. It provides code re-usability. It is used to achieve runtime polymorphism.
3. Inheritance
Inheritance is the process of creating a new Class, called the Derived Class, from the existing class, called the Base Class.
The “inheritance concept” can be grouped into two categories:
- derived class (child) – the class that inherits from another class
- base class (parent) – the class being inherited from

Different Types of Inheritance
Object-Oriented Programming (OOP) support the six different types of inheritance as given below:
- Single Inheritance
- Multi-level Inheritance
- Multiple Inheritance
- Multi-path Inheritance
- Hierarchical Inheritance
- Hybrid Inheritance

4. Polymorphism
Polymorphism means “many forms”, and it occurs when we have many classes that are related to each other by inheritance.
If one task is performed in different ways, it is known as polymorphism.
Examples:
- To convince the customer differently
- To draw something, for example, shape, triangle, rectangle, etc.
- To speak something; for example, a cat speaks meow, dog barks woof, etc.
Generally, method overloading and method overriding are used to achieve polymorphism.