OOP Concepts · Lesson 8 of 8 · Updated ·
Top OOP Interview Questions — Short Answers With Examples
Revise these before any technical round. Give the one-line answer, then a real example — that combination impresses interviewers.
Fundamentals
1. What is OOP? A programming style that organises code into objects combining data and behaviour, built on four pillars: encapsulation, abstraction, inheritance, polymorphism.
2. Class vs object? A class is a blueprint; an object is an instance with its own state. Example: Car class; your Swift and my Nexon are objects.
3. What is a constructor? A special method that initialises a new object; same name as the class (Java) or __init__ (Python); no return type.
4. Can a constructor be overloaded? private? Yes and yes — private constructors are used in Singleton and utility classes.
5. What is this / self? A reference to the current object.
The pillars
6. Encapsulation vs abstraction? Encapsulation protects data (private fields + methods); abstraction hides complexity (interfaces). Example: ATM — the cash vault is encapsulated; the screen menu is the abstraction.
7. Types of inheritance? Single, multilevel, hierarchical, multiple, hybrid. Java: multiple only through interfaces.
8. Why doesn't Java support multiple inheritance of classes? To avoid the diamond problem (ambiguous inherited methods).
9. Overloading vs overriding? Overloading: same name, different parameters, compile time. Overriding: same signature in a subclass, runtime.
10. Can static methods be overridden? No — they are hidden, not overridden (no runtime dispatch).
11. What is dynamic dispatch? Choosing which overridden method to run based on the actual object at runtime.
Abstraction tools
12. Abstract class vs interface? Abstract class: can have state, constructors and code; single inheritance. Interface: a contract; a class can implement many. Use abstract class for shared code, interface for capabilities.
13. Can an abstract class have a constructor? Yes — it runs when a subclass object is created.
Relationships and design
14. Aggregation vs composition? Both are has-a. Aggregation: parts can live alone (Team–Player). Composition: parts die with the whole (House–Room).
15. Composition over inheritance — why? Less coupling; you can change parts at runtime; avoids fragile deep hierarchies.
16. What are SOLID principles? Single responsibility, Open/closed, Liskov substitution, Interface segregation, Dependency inversion.
17. Name a design pattern you've used. e.g. Singleton for config, Factory for creating payment handlers, Observer for notifications.
Tricky ones
18. What is the output?
class Parent {
String name = "parent";
String who() { return "Parent.who"; }
}
class Child extends Parent {
String name = "child";
@Override String who() { return "Child.who"; }
}
public class Main {
public static void main(String[] args) {
Parent p = new Child();
System.out.println(p.name + " " + p.who());
}
}
parent Child.who
Why: methods are polymorphic (runtime), but fields are not — field access uses the variable's declared type (Parent).
19. Is Java 100% object-oriented? No — it has primitive types (int, char) that aren't objects, and static members.
20. What is an object's identity, state and behaviour? Identity = which object (its reference); state = field values; behaviour = methods.
How to answer
- One-line definition.
- A real-life or code example.
- A trade-off or a "when not to use" — shows depth.
Common mistakes
- Defining terms without examples.
- Mixing up abstraction and encapsulation.
- Saying fields are overridden like methods.
Quick recap
- Revise: pillars, class vs object, overloading vs overriding, abstract class vs interface, aggregation vs composition, SOLID, a few patterns.
- Answer: definition → example → trade-off.