What is inheritance in OOP?

Why Interviewers Ask This

This question tests conceptual clarity. Interviewers want to hear a precise, confident definition before moving to more complex OOP Concepts topics. It also reveals how well you can explain technical ideas to non-experts.

Answer

Inheritance is a mechanism where a new class (subclass/derived/child) acquires the properties and behaviors of an existing class (superclass/base/parent). It models an "is-a" relationship and enables code reuse. Types of inheritance: (1) Single: one class inherits from one parent (Java supports this); (2) Multiple: one class inherits from multiple parents (C++, Python support this; Java uses interfaces instead); (3) Multilevel: A → B → C (C inherits from B which inherits from A); (4) Hierarchical: multiple classes inherit from the same parent; (5) Hybrid: combination. Example (Java): class Vehicle { protected String brand; protected int speed; public Vehicle(String brand) { this.brand = brand; this.speed = 0; } public void accelerate(int amount) { this.speed += amount; } public void brake(int amount) { this.speed = Math.max(0, speed - amount); } } class Car extends Vehicle { private int doors; public Car(String brand, int doors) { super(brand); // Call parent constructor this.doors = doors; } @Override public String toString() { return brand + " (Car, " + doors + " doors) at " + speed + " km/h"; } } class Motorcycle extends Vehicle { private boolean hasSidecar; public Motorcycle(String brand, boolean hasSidecar) { super(brand); this.hasSidecar = hasSidecar; } }. super keyword: call parent constructor or method. Method overriding: redefine inherited method in child class. When NOT to use inheritance: "is-a" must be true. Dog is an Animal ✓. Car is an Engine ✗ (use composition). Avoid deep inheritance hierarchies (>3 levels) — brittle.

Pro Tip

Back up your answer with a specific project or situation. Saying 'In my last OOP Concepts project, I used this when...' immediately makes your answer more credible and memorable.