OOP

Object-Oriented Programming Interview Questions

Understand the four pillars of OOP, SOLID principles, and how to apply them in technical interviews. Covers encapsulation, inheritance, polymorphism, and abstraction with real examples.

Object-oriented programming (OOP) questions appear in almost every software engineering interview, from fresh-grad roles to senior positions. Interviewers use these questions to probe how deeply you understand software design — not just syntax, but why OOP concepts exist and when they genuinely help.

The four pillars (encapsulation, inheritance, polymorphism, abstraction) are the vocabulary; the SOLID principles are the judgement. Knowing both lets you reason out loud about trade-offs, which is exactly what interviewers want to hear.

Key Concepts

Encapsulation

Bundle data and the methods that operate on it inside a class, and hide implementation details behind a public interface. This means marking fields private and exposing only what callers need. The payoff: you can change the internals without breaking any code that depends on the class.

Inheritance

A subclass inherits the state and behaviour of its parent, then extends or overrides it. Inheritance models 'is-a' relationships. Overuse causes fragile hierarchies — if the parent changes, every subclass breaks. Prefer composition ('has-a') over deep inheritance chains.

Polymorphism

The same interface, multiple implementations. At runtime, the correct method is dispatched based on the object's actual type (dynamic dispatch). This is what makes code open to extension without modification — you can add a new subclass and existing code just works.

Abstraction

Expose what something does, hide how it does it. Abstract classes and interfaces define contracts. Callers depend on the abstraction, not the concrete implementation. This is the mechanism behind dependency inversion and what makes testing and swapping implementations easy.

SOLID Principles

Single Responsibility: a class should have one reason to change. Open/Closed: open for extension, closed for modification. Liskov Substitution: subtypes must be substitutable for their base type. Interface Segregation: many specific interfaces beat one fat interface. Dependency Inversion: depend on abstractions, not concretions. Violations of these principles are a common interview discussion topic.

Composition vs Inheritance

Composition (giving a class a field of another type) is usually more flexible than inheritance. It avoids tight coupling between parent and child, makes unit testing easier (you can inject fakes), and sidesteps the fragile base-class problem. A common interview follow-up: 'When would you still choose inheritance?'

Sample Interview Questions

What is the difference between an abstract class and an interface?

Explain the Liskov Substitution Principle with an example.

Why is 'favour composition over inheritance' good advice?

Ready to test yourself?

Apply what you've read with a timed 10-question quiz on OOP.

Start OOP Quiz →