What is inheritance in Java?
Why Interviewers Ask This
This question tests conceptual clarity. Interviewers want to hear a precise, confident definition before moving to more complex Java topics. It also reveals how well you can explain technical ideas to non-experts.
Answer
Inheritance is an OOP mechanism where a class (subclass/child) acquires the properties and behaviors of another class (superclass/parent) using the extends keyword. This promotes code reuse — common fields and methods are defined once in the parent and reused in all children. Example: class Dog extends Animal — Dog inherits all non-private fields and methods of Animal. Java supports single inheritance for classes (a class can extend only one class) but multiple inheritance through interfaces. The super keyword accesses parent class members. Every class in Java implicitly extends Object.
Pro Tip
Before answering, structure your response: one-line definition → real-world analogy → concrete example from a project. This makes even complex Java answers easy to follow.