100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Java

OOP Interview Questions in Java

A focused roundup of Java OOP interview questions covering the four pillars — encapsulation, inheritance, polymorphism, abstraction — plus interface vs abstract class and overloading vs overriding.

Interview PrepIntermediate15 min readJul 7, 2026
Analogies

1. Introduction

Object-oriented programming questions are the backbone of most Java interviews because they reveal whether a candidate can design software, not just write syntax. This roundup drills into the four OOP pillars — encapsulation, inheritance, polymorphism, and abstraction — along with the classic interface-vs-abstract-class and overloading-vs-overriding comparisons.

🏏

Cricket analogy: A talent scout at an IPL trial doesn't just watch a batsman's shots but pressure-tests footwork, shot selection, and temperament—OOP interviews similarly probe encapsulation, inheritance, polymorphism, and abstraction, not just syntax recall.

Every answer below is written to be precise and consistent with core Java semantics: Java supports single inheritance of classes but multiple inheritance of interface types, which resolves a lot of interviewer follow-up traps.

🏏

Cricket analogy: A player like Virat Kohli can only be contracted to one IPL franchise at a time (single inheritance of class) but can simultaneously endorse many brands like Puma and MRF (multiple interfaces), which is exactly how Java structures class versus interface inheritance.

2. Syntax

java
abstract class Shape {
    abstract double area();
    void describe() { System.out.println("A shape with area " + area()); }
}

class Circle extends Shape {
    double radius;
    Circle(double r) { radius = r; }
    double area() { return Math.PI * radius * radius; }
}
java
interface Flyable { void fly(); }
interface Swimmable { void swim(); }

class Duck implements Flyable, Swimmable {
    public void fly() { System.out.println("Duck flies"); }
    public void swim() { System.out.println("Duck swims"); }
}

3. Explanation

OOP questions are usually framed as 'explain X with a real-world example' or 'compare X and Y'. Interviewers listen for the mechanism, not just the buzzword: for encapsulation, that means private fields plus public getters/setters that can validate input; for polymorphism, that means one reference type invoking different implementations depending on the actual object at runtime (dynamic dispatch).

🏏

Cricket analogy: Encapsulation is like a team manager keeping player fitness data private and only releasing it through an official statement that validates accuracy, while polymorphism is a captain calling 'catch it' and each fielder—Kohli or Jadeja—reacting differently based on their actual position.

A frequent trap is conflating overloading (compile-time polymorphism) with overriding (runtime polymorphism) — always name which kind of polymorphism you mean. Another trap is claiming Java supports 'multiple inheritance' loosely; be precise: a class can extend only one class, but can implement any number of interfaces.

🏏

Cricket analogy: Confusing overloading with overriding is like confusing a batsman choosing which bat to use before the match (decided in advance, like overloading) with a fielder reacting differently to the ball's actual trajectory during play (decided at runtime, like overriding).

Exam/interview strategy: for every OOP pillar, be ready to state (1) a one-line definition, (2) the Java keyword or mechanism that implements it (private/getters, extends, method overriding, abstract/interface), and (3) a short real-world analogy — this three-part structure covers almost every follow-up question.

4. Example

java
abstract class Employee {
    protected String name;
    Employee(String name) { this.name = name; }
    abstract double calculateBonus();
    void printBonus() {
        System.out.println(name + " bonus: " + calculateBonus());
    }
}

class Manager extends Employee {
    Manager(String name) { super(name); }
    double calculateBonus() { return 5000; }
}

class Developer extends Employee {
    Developer(String name) { super(name); }
    double calculateBonus() { return 3000; }
}

public class OopDemo {
    public static void main(String[] args) {
        Employee[] staff = { new Manager("Asha"), new Developer("Ravi") };
        for (Employee e : staff) {
            e.printBonus();
        }
    }
}

5. Output

text
Asha bonus: 5000.0
Ravi bonus: 3000.0

6. Key Takeaways

  • Encapsulation means bundling data with the methods that operate on it and restricting direct access via private fields plus public getters/setters.
  • Inheritance lets a subclass reuse and extend a superclass's fields and methods using extends; Java allows only single class inheritance but multiple interface implementation.
  • Polymorphism appears as compile-time (method overloading) and runtime (method overriding via dynamic dispatch) — the Employee array example above demonstrates runtime polymorphism.
  • Abstraction hides implementation detail behind a simpler contract, achieved in Java via abstract classes (partial implementation) or interfaces (pure contract, plus default methods since Java 8).
  • An abstract class can hold state and constructors and supports single inheritance; an interface defines a contract a class can implement in addition to extending one class.
  • Overloading is resolved at compile time based on the method signature; overriding is resolved at runtime based on the actual object type, which is exactly how the printBonus() loop dispatches to the correct calculateBonus().

Practice what you learned

Was this page helpful?

Topics covered

#Java#JavaProgrammingStudyNotes#Programming#OOPInterviewQuestionsInJava#OOP#Interview#Questions#Syntax#StudyNotes#SkillVeris