OOP Interview Question

What are the four pillars of OOP?

Updated 2026-07-10 · Beginner friendly
Quick answer

The four pillars of Object Oriented Programming are encapsulation, abstraction, inheritance, and polymorphism. Encapsulation hides data behind methods, abstraction hides complexity behind a simple interface, inheritance lets one class reuse another, and polymorphism lets the same call behave differently for different objects.

1. Encapsulation

Encapsulation means keeping data and the methods that use it inside one class, and controlling access from the outside. You make fields private and expose safe methods to read or change them. Think of a capsule that protects what is inside.

class BankAccount {
    private double balance;            // hidden
    public void deposit(double amt) {  // controlled access
        if (amt > 0) balance += amt;
    }
}

2. Abstraction

Abstraction means showing only what a user needs and hiding the messy details. When you drive a car you use the steering wheel and pedals. You do not need to know how the engine burns fuel. In code you expose a simple method and hide the complex logic behind it.

3. Inheritance

Inheritance lets a new class reuse the fields and methods of an existing class. The existing class is the parent and the new one is the child. A Dog class can inherit from an Animal class and automatically get its eat and sleep methods.

class Animal {
    void eat() { System.out.println("eating"); }
}
class Dog extends Animal {   // Dog reuses eat()
    void bark() { System.out.println("woof"); }
}

4. Polymorphism

Polymorphism means one name behaving in many forms. The same method call can do different things depending on the object. A draw method on a Shape can draw a circle or a square based on which shape it actually is.

In the interview

A common trick from interviewers is to ask you to remember all four and give one line for each. Use the memory aid A PIE, which stands for Abstraction, Polymorphism, Inheritance, Encapsulation. Then be ready to give a one example for any pillar they pick.

Want the full OOP guide?

Read every OOP concept with notes, diagrams, and code in one place. Track your progress as you go.

Open the OOP guide All OOP questions