Top OOPS Concepts Interview Questions and Answers

Looking to master OOPS for your upcoming interviews?
Object-Oriented Programming (OOPS) is a critical topic for every software developer and programming interview. In this post, we cover the 30 Most Important OOPS Interview Questions with Answers and Examples to strengthen your fundamentals and coding confidence. These Top OOPS Concepts Interview Questions and Answers Explained with Examples will help you understand abstraction, inheritance, polymorphism, and encapsulation deeply.

Whether you are preparing for Java, C++, or Python interviews, these OOPS Interview Questions: 30 Must-Know Questions with Examples (2025 Updated) will guide you step-by-step towards success.

🔗 Recommended Read: Top Interview Questions For Java in TCS for your full-stack and backend interview preparation.

1. What is Object-Oriented Programming?

Answer: OOP is a programming paradigm based on the concept of “objects”, which contain data (fields) and code (methods). It focuses on reusability, scalability, and efficiency.

Example:

class Car {

    String color;

    void drive() {

        System.out.println(“Car is driving”);

    }

}

2. What are the four pillars of OOP?

Answer:

  1. Encapsulation – Wrapping data and methods in a single unit (class).

     

  2. Inheritance – Acquiring properties from another class.

     

  3. Polymorphism – Same name but different behaviours.

     

  4. Abstraction – Hiding implementation details and showing only functionality.

     

3. Explain Encapsulation with an example.

Answer: Encapsulation binds data and methods together while keeping data safe from outside interference.

Example:

class Employee {

    private int salary; // private variable

    public void setSalary(int s) {

        salary = s;

    }

    public int getSalary() {

        return salary;

    }

}

Here, salary is hidden from outside access directly.

4. Explain Inheritance with an example.

Answer: Inheritance is acquiring properties of another class.

Example:

class Animal {

    void eat() {

        System.out.println(“Eating…”);

    }

}

class Dog extends Animal {

    void bark() {

        System.out.println(“Barking…”);

    }

}

Here, Dog inherits Animal methods.

5. Explain Polymorphism with an example.

Answer: Polymorphism means many forms.

  • Compile-time (Method Overloading)

     

class Calculator {

    int add(int a, int b) { return a + b; }

    double add(double a, double b) { return a + b; }

}

  • Run-time (Method Overriding)

     

class Animal {

    void sound() { System.out.println(“Animal sound”); }

}

class Cat extends Animal {

    void sound() { System.out.println(“Meow”); }

}

6. Explain Abstraction with an example.

Answer: Abstraction hides complexity and shows only essential features.

Example:

abstract class Shape {

    abstract void draw();

}

class Circle extends Shape {

    void draw() {

        System.out.println(“Drawing Circle”);

    }

}

7. What is a class?

Answer: A class is a blueprint for creating objects, containing variables and methods.

Example:

class Student {

    String name;

    int rollNo;

}

8. What is an object?

Answer: An object is an instance of a class with real-time existence.

Example:

Student s1 = new Student();

9. What is method overloading?

Answer: Same method name with different parameter lists in the same class.

Example:

class MathOp {

    int multiply(int a, int b) { return a * b; }

    double multiply(double a, double b) { return a * b; }

}

10. What is method overriding?

Answer: A child class provides a specific implementation of a method already defined in its parent class.

Example:

class Vehicle {

    void run() { System.out.println(“Vehicle is running”); }

}

class Bike extends Vehicle {

    void run() { System.out.println(“Bike is running safely”); }

}

11. Difference between overloading and overriding?

Overloading

Overriding

Compile-time polymorphism

Run-time polymorphism

Same method name, different parameters

Same method name and parameters in child class

Within same class

Different classes (inheritance)

12. What is constructor?

Answer: A special method called when an object is created to initialize it.

Example:

class Car {

    Car() {

        System.out.println(“Car created”);

    }

}

13. What is constructor overloading?

Answer: Multiple constructors in a class with different parameter lists.

class Person {

    Person() { }

    Person(String name) { }

}

14. What is ‘super’ keyword?

Answer: Used to refer immediate parent class object.

Example:

class Parent {

    void show() { System.out.println(“Parent”); }

}

class Child extends Parent {

    void show() {

        super.show(); // calls Parent show()

        System.out.println(“Child”);

    }

}

15. What is ‘this’ keyword?

Answer: Refers to current class object.

class Demo {

    int x;

    Demo(int x) {

        this.x = x; // assigns local x to class x

    }

}

16. What is an abstract class?

Answer: An abstract class is a class that is declared with the abstract keyword and cannot be instantiated directly. It is meant to be inherited by other classes.

Detailed Explanation:

  • An abstract class may or may not contain abstract methods.

     

  • An abstract method is a method without a body (implementation) that must be overridden in the subclass.

     

  • Abstract classes can have:

     

    • Abstract methods (without body)

       

    • Concrete methods (with body)

       

    • Constructors

       

    • Fields (variables)

Key Points:

  • Cannot create an object of an abstract class directly.
  • Used to provide a base for subclasses with some common functionality.
  • Subclasses must implement all abstract methods of the abstract class unless they are also abstract.
  • Supports constructors, which are called when a subclass object is created.

17. What is an interface?

Answer: An interface contains abstract methods and is used for achieving complete abstraction.

Example:

interface Drawable {

    void draw();

}

class Rectangle implements Drawable {

    public void draw() {

        System.out.println(“Drawing Rectangle”);

    }

}

18. Difference between abstract class and interface?

Abstract Class

Interface

Can have abstract and concrete methods

Only abstract methods (Java 7), default/static (Java 8+)

Can have constructor

No constructor

Supports single inheritance

Supports multiple inheritance

19. What is multiple inheritance?

Answer: A class inheriting more than one class. Not supported directly in Java due to ambiguity issues but can be achieved using interfaces.

Detailed Explanation:

  • The derived class inherits features (methods and variables) of multiple parent classes.

     

  • C++ supports multiple inheritance directly with classes.

     

  • Java does not support multiple inheritance with classes to avoid ambiguity issues like the Diamond Problem.

Diagram:

  A    B

   \  /

    C

20. What is hybrid inheritance?

Answer: Hybrid inheritance is a combination of two or more types of inheritance (single, multiple, multilevel, hierarchical) in a single program to form a complex inheritance structure.

Detailed Explanation:

  • Hybrid inheritance combines different inheritance types to leverage their benefits.

     

  • It often creates diamond problems if multiple inheritance is involved (especially in C++).

Explanation of Example:

✔️ Here:

  • B and C inherit from A (hierarchical inheritance).

     

  • D inherits from both B and C (multiple inheritance).

     

➡ Thus, it is a hybrid of hierarchical + multiple inheritance.

Diagram:

     A

    / \

   B   C

    \ /

     D

21. What is hierarchical inheritance?

Answer: Hierarchical inheritance is a type of inheritance in which multiple subclasses inherit from a single superclass.

Detailed Explanation:

  • One parent (base) class is extended by two or more child (derived) classes.

     

  • Each subclass inherits the properties and behaviours of the parent class independently.

     

  • Common functionalities are defined in the parent class and shared by all child classes.

        

      Animal

       /      \

    Dog       Cat

✔ ️ Dogs and Cats  both inherit from Animals.

22. What is multilevel inheritance?

Answer: Multilevel inheritance is a type of inheritance where a class is derived from a derived class, forming a chain of inheritance levels.

Detailed Explanation:

  • In multilevel inheritance, a class inherits from another derived class, which itself inherits from a base class.

     

  • The inheritance forms a parent → child → grandchild hierarchy.

class A { }

class B extends A { }

class C extends B { }

23. Can we override static methods?

Answer: No, static methods belong to class, not objects.

24. Can constructor be inherited?

Answer: No, constructors are not inherited.

25. What is final keyword?

Answer:

  • Final variable – cannot be changed.

     

  • Final method – cannot be overridden.

     

  • Final class – cannot be inherited.

     

26. What is a static variable?

Answer: A static variable is a variable that belongs to the class itself rather than to any specific instance (object). It is shared across all objects of that class.

Detailed Explanation:

  • Declared using the static keyword.

     

  • Memory is allocated only once, when the class is loaded.

     

  • All instances of the class share the same static variable.

class Employee {

    int empId;

    String name;

    static String company = “TechCorp”; // static variable

    Employee(int id, String n) {

        empId = id;

        name = n;

    }

    void display() {

        System.out.println(empId + ” ” + name + ” ” + company);

    }

}

public class Test {

    public static void main(String[] args) {

        Employee e1 = new Employee(101, “Alice”);

        Employee e2 = new Employee(102, “Bob”);

        e1.display(); // Output: 101 Alice TechCorp

        e2.display(); // Output: 102 Bob TechCorp

        // Changing static variable using class name

        Employee.company = “InnoTech”;

        e1.display(); // Output: 101 Alice InnoTech

        e2.display(); // Output: 102 Bob InnoTech

    }

}

27. What is the difference between aggregation and composition?

Aggregation

Composition

Has-A relationship with weaker association

Stronger association

Child can exist independently

Child cannot exist independently

Example:

  • Aggregation – Department has students.

     

  • Composition – House has rooms (rooms can’t exist without house).

     

28. What is dynamic method dispatch?

Answer: Dynamic Method Dispatch is the process in which a call to an overridden method is resolved at runtime rather than compile-time. It is also known as runtime polymorphism.

Detailed Explanation:

  • When a superclass reference variable refers to a subclass object and an overridden method is called, Java determines which version of the method to execute based on the actual object type (not reference type) at runtime.

     

  • This mechanism allows Java to support runtime polymorphism, enabling flexible and dynamic behaviour of objects.

class Animal {

    void sound() {

        System.out.println(“Animal makes a sound”);

    }

}

class Dog extends Animal {

    void sound() {

        System.out.println(“Dog barks”);

    }

}

public class Test {

    public static void main(String[] args) {

        Animal a; // reference of type Animal

        a = new Animal();

        a.sound(); // Output: Animal makes a sound

        a = new Dog();

        a.sound(); // Output: Dog barks

    }

}

 

29. What is an inner class?

Answer: An inner class is a class defined within another class in Java (or similar languages). It is also called a nested class.

Detailed Explanation:

  • An inner class is associated with its outer class.

     

  • It can access the members (even private) of the outer class directly.

     

  • It is mainly used for logical grouping, encapsulation, and more readable code.

Example:

class Outer {

    class Inner {

        void display() { System.out.println(“Inner class”); }

    }

}

30. What is object slicing?

Answer: Object slicing occurs when an object of a derived (child) class is assigned to an object of its base (parent) class, causing the derived class-specific members to be “sliced off”, and only the base part remains.

Key Points:

No object slicing in Java because:

  1. Java uses references for objects, not value copying.

     

  2. Even if assigned to a base class reference, the underlying object remains the derived class object.

     

  3. Runtime polymorphism ensures overridden methods of derived class are called.

class Base {

    int x = 10;

    void display() { System.out.println(“Base x: ” + x); }

}

class Derived extends Base {

    int y = 20;

    void display() { System.out.println(“Base x: ” + x + “, Derived y: ” + y); }

}

public class Test {

    public static void main(String[] args) {

        Derived d = new Derived();

        Base b = d; // No object slicing, b is a reference to d

        b.display(); // Calls Derived display() due to dynamic dispatch

        // b.y is not accessible as b is a Base reference

        // System.out.println(b.y); // Compilation error

    }

}

In this article, we covered the Top OOPS Concepts Interview Questions and Answers Explained with Examples to give you a strong command over object-oriented programming. These 30 Most Important OOPS Interview Questions with Answers and Examples are frequently asked in top product and service-based companies. Make sure to revise them thoroughly and practice with coding examples to gain clarity on each concept.

For continued learning, check out our OOPS Interview Questions: 30 Must-Know Questions with Examples (2025 Updated) and other interview preparation guides at Top Interview Questions.

Keep practising and stay confident. Your dream job awaits!

 

👉 Explore related interview guides to level up your preparation:

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top