The four pillars of OOP — Encapsulation, Inheritance, Polymorphism, and Abstraction — appear in virtually every Java interview. But most candidates give textbook definitions. The interviewers who ask "what is polymorphism?" are not testing your memory of a definition; they're testing whether you can explain what the JVM actually does and when you'd use it in production code.

Here are the questions interviewers actually ask in 2026, with the technical precision they're looking for.

Q1: Explain polymorphism with a real example

Weak answer: "Polymorphism means one interface, multiple implementations."

Strong answer: "Polymorphism lets you write code against an interface or superclass, and the JVM resolves at runtime which concrete implementation to call. This is called dynamic dispatch. For example, I have a PaymentProcessor interface with a process() method. My checkout code takes a PaymentProcessor parameter and calls process(). At runtime, depending on whether the user chose UPI, credit card, or net banking, a different implementation runs — without the checkout code knowing or caring which one."

Java — polymorphism example
interface PaymentProcessor {
    boolean process(double amount);
}

class UPIProcessor implements PaymentProcessor {
    public boolean process(double amount) {
        System.out.println("Processing UPI payment: " + amount);
        return true;
    }
}

class CardProcessor implements PaymentProcessor {
    public boolean process(double amount) {
        System.out.println("Processing card payment: " + amount);
        return true;
    }
}

// Checkout code — doesn't know which implementation runs
public void checkout(PaymentProcessor processor, double amount) {
    if (!processor.process(amount)) {
        throw new RuntimeException("Payment failed");
    }
}

Q2: Abstract class vs Interface — when do you use each?

This is the question that separates candidates who've used Java from those who've read about it.

AspectAbstract classInterface
InheritanceSingle (extends)Multiple (implements)
ConstructorCan have constructorsNo constructors
StateCan have instance variablesOnly constants (static final)
Default methodsYes (regular methods)Yes (Java 8+ with default keyword)
Access modifiersAnyMethods are public by default
Use whenShared state + partial implementationContract/capability without state

Model answer: "I use an abstract class when I have shared state (instance variables) or a partial implementation that subclasses extend. I use an interface when I'm defining a contract — a capability that multiple unrelated classes might implement. Since Java 8 added default methods, interfaces are more capable, but they still can't have state. If I have a template method pattern — common algorithm steps, specific steps vary — that's an abstract class. If I have a role or capability that cuts across the hierarchy (Serializable, Comparable, Runnable), that's an interface."

Q3: Method overloading vs method overriding

Java
// Overloading — same class, same method name, DIFFERENT parameters
// Resolved at COMPILE time (static dispatch)
class Calculator {
    int add(int a, int b)          { return a + b; }
    double add(double a, double b) { return a + b; }  // overloaded
    int add(int a, int b, int c)   { return a + b + c; }  // overloaded
}

// Overriding — subclass provides DIFFERENT implementation of parent method
// Resolved at RUNTIME (dynamic dispatch)
class Animal { void sound() { System.out.println("Some sound"); } }
class Dog extends Animal {
    @Override
    void sound() { System.out.println("Woof"); }  // overridden
}

Key point: overloading is resolved at compile time; overriding is resolved at runtime. Use @Override annotation always — it makes overriding explicit and catches typos at compile time.

Q4: Encapsulation — what it actually means in production

Definition: Bundling data (fields) and methods that operate on that data into one class, and restricting direct access to some of the class's components.

In practice: private fields with public getters/setters — but more importantly, validation logic inside the setter so the object is always in a valid state.

Java — encapsulation with validation
public class BankAccount {
    private double balance;  // private — not accessible directly

    public void deposit(double amount) {
        if (amount <= 0) throw new IllegalArgumentException("Must be positive");
        this.balance += amount;
    }

    public void withdraw(double amount) {
        if (amount > balance) throw new InsufficientFundsException();
        this.balance -= amount;
    }

    public double getBalance() { return this.balance; }
    // NO setBalance() — only controlled mutation through deposit/withdraw
}

Q5: Access modifiers

ModifierSame classSame packageSubclassOther
private
(default/package)
protected
public

Q6: What is the diamond problem and how does Java handle it?

The diamond problem: if class D inherits from B and C, and both B and C inherit from A and override the same method, which version does D get?

Java avoids this by not allowing multiple inheritance of classes. You can implement multiple interfaces, and since Java 8 interfaces can have default methods, a form of the diamond problem can arise — Java handles it by requiring the implementing class to explicitly override the conflicting default method and call the desired version with InterfaceName.super.method().

RELATED READING The Polymorphism lesson, Inheritance lesson, and Abstraction lesson in the Java tutorial section cover these topics with more code examples and practice exercises.