Object-Oriented Programming Interview Questions

Master the four pillars of OOP, design patterns, and SOLID principles essential for technical interviews.

What is Object-Oriented Programming?

Click to explore the answer and key concepts

Done

What are the four pillars of OOP?

Click to explore the answer and key concepts

Done

What is a Class?

Click to explore the answer and key concepts

Done

What is an Object?

Click to explore the answer and key concepts

Done

What is Encapsulation?

Click to explore the answer and key concepts

Done

What is Abstraction?

Click to explore the answer and key concepts

Done

What is Inheritance?

Click to explore the answer and key concepts

Done

What is Polymorphism?

Click to explore the answer and key concepts

Done

What are the types of Polymorphism?

Click to explore the answer and key concepts

Done

What is Method Overloading?

Click to explore the answer and key concepts

Done

What is Method Overriding?

Click to explore the answer and key concepts

Done

What is the difference between Overloading and Overriding?

Click to explore the answer and key concepts

Done

What is a Constructor?

Click to explore the answer and key concepts

Done
A constructor is a special method that is automatically called when an object is created. It initializes the object's state and allocates resources. Real Example: • Car constructor: Sets initial speed to 0, fuel to full • BankAccount constructor: Sets initial balance, generates account number • Cannot be called directly, called automatically with 'new' • Same name as class, no return type • Like birth - sets up initial state of object Java Code Example:
public class Car {
    private String model;
    private int speed;
    private boolean engineStarted;
    
    // Default constructor (no parameters)
    public Car() {
        this.model = "Unknown";
        this.speed = 0;
        this.engineStarted = false;
        System.out.println("Car created with default constructor");
    }
    
    // Parameterized constructor
    public Car(String model) {
        this.model = model;
        this.speed = 0;
        this.engineStarted = false;
        System.out.println("Car created: " + model);
    }
    
    // Constructor with multiple parameters
    public Car(String model, int initialSpeed) {
        this.model = model;
        this.speed = initialSpeed;
        this.engineStarted = true;
        System.out.println("Car created: " + model + " at speed " + initialSpeed);
    }
    
    // Constructor overloading
    public Car(String model, String color) {
        this.model = model;
        this.speed = 0;
        this.engineStarted = false;
        System.out.println("Car created: " + color + " " + model);
    }
}

public class ConstructorDemo {
    public static void main(String[] args) {
        Car car1 = new Car();                    // Default constructor
        Car car2 = new Car("Toyota");           // One parameter
        Car car3 = new Car("Honda", 50);        // Two parameters
        Car car4 = new Car("BMW", "Red");      // Different parameters
    }
}

Key Points:

Object initializationAutomatic invocationSame name as classNo return type

What are the types of Constructors?

Click to explore the answer and key concepts

Done

What is a Destructor?

Click to explore the answer and key concepts

Done

What is the 'this' keyword?

Click to explore the answer and key concepts

Done

What is the 'super' keyword?

Click to explore the answer and key concepts

Done

What is the difference between 'this' and 'super'?

Click to explore the answer and key concepts

Done

What is an Abstract Class?

Click to explore the answer and key concepts

Done

What is an Interface?

Click to explore the answer and key concepts

Done

What is the difference between Abstract Class and Interface?

Click to explore the answer and key concepts

Done

What is Multiple Inheritance?

Click to explore the answer and key concepts

Done

What is the Diamond Problem?

Click to explore the answer and key concepts

Done

What is Composition?

Click to explore the answer and key concepts

Done

What is Aggregation?

Click to explore the answer and key concepts

Done

What is Association?

Click to explore the answer and key concepts

Done

What is Coupling?

Click to explore the answer and key concepts

Done

What is Cohesion?

Click to explore the answer and key concepts

Done

What is SOLID Principles?

Click to explore the answer and key concepts

Done

What is Design Patterns?

Click to explore the answer and key concepts

Done

What is Singleton Pattern?

Click to explore the answer and key concepts

Done

What is Factory Pattern?

Click to explore the answer and key concepts

Done

What is Observer Pattern?

Click to explore the answer and key concepts

Done