Interview Q&A / Object-Oriented Programming

BeginnerQuick answer1 min readUpdated 3 Oct 2026

What is the difference between abstraction and encapsulation?

SHORT ANSWER

Abstraction decides what to show: it exposes a simple view and hides complexity. Encapsulation decides how to protect: it bundles data with methods and restricts access to it.

Explain it simply

A car's steering wheel and pedals are abstraction: you say "turn" and "go faster" without knowing about the engine. The sealed engine bay with a bonnet lock is encapsulation: parts are enclosed and guarded so they are not tampered with.

Abstraction works at the design level (which operations make sense). Encapsulation works at the implementation level (how state is held and guarded). They support each other.

Example

java
interface UpiPayment {                       // abstraction: what you can do
    boolean pay(String vpa, int rupees);
}

class BankUpi implements UpiPayment {
    private int dailyLimit = 100000;         // encapsulation: guarded detail
    private int spentToday = 0;

    public boolean pay(String vpa, int rupees) {
        if (spentToday + rupees > dailyLimit) return false;
        spentToday += rupees;
        return true;
    }
}

Callers see only pay. The limit logic is hidden by private.

What to say in the interview

"Abstraction hides complexity by exposing only essential operations, typically through interfaces and abstract classes. Encapsulation hides internal state by making it private and controlling access through methods. One is about the design of the interface, the other about protecting the implementation."

Common mistakes

  • Saying they are the same thing with different names.

#abstraction#encapsulation#oop

Related questions

Practise more Object-Oriented Programming questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open Object-Oriented Programming quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.