Fifteen common OOP interview questions
- What are the four pillars of OOP?
- What is the difference between a class and an object?
- Encapsulation versus abstraction?
- What types of inheritance exist, and what is the diamond problem?
- Compile-time versus runtime polymorphism?
- Method overloading versus overriding?
- Interface versus abstract class?
- Why prefer composition over inheritance?
- What are constructors and destructors? What is constructor chaining?
- What do access modifiers do?
- What is the difference between static and instance members?
- What are the SOLID principles?
- What is coupling and cohesion?
- What is a shallow versus deep copy?
- Design classes for a simple library system.
The four pillars, briefly
- Encapsulation: bundle data with the methods that operate on it and restrict direct access, so an object controls its own state (a BankAccount changes its balance only through deposit and withdraw).
- Abstraction: expose what an object does, hide how (you call sort() without knowing the algorithm).
- Inheritance: a class reuses and extends another (a SavingsAccount is an Account).
- Polymorphism: one interface, many implementations — calling area() on any Shape runs the right version for circles or squares.
Distinctions interviewers love
| Pair | Key difference |
|---|---|
| Overloading vs overriding | Same name, different parameters, resolved at compile time vs subclass redefines a parent method, resolved at runtime |
| Interface vs abstract class | Pure contract (a class can implement many) vs partial implementation with shared state (usually single inheritance) |
| Composition vs inheritance | Has-a, flexible and swappable vs is-a, tight coupling to the parent |
| Static vs instance | Belongs to the class vs belongs to each object |
| Shallow vs deep copy | Copies references vs copies the referenced objects too |
SOLID in plain terms
- Single responsibility: one reason to change per class.
- Open/closed: extend behaviour by adding code, not editing working code.
- Liskov substitution: a subclass must work anywhere its parent does (a Square that breaks Rectangle's setWidth contract violates it).
- Interface segregation: many small interfaces beat one that forces unused methods.
- Dependency inversion: depend on abstractions, so you can swap a database or payment provider without rewriting callers.
Common traps
- Calling encapsulation “making fields private”: private fields are a mechanism; the point is that the object enforces its own invariants.
- Using inheritance for code reuse alone: if the is-a relationship isn't true, composition is the better answer.
- Confusing abstraction with abstract classes: abstraction is the idea of hiding detail; abstract classes are one language feature for it.
- Forgetting that constructors aren't inherited in Java and C#, which surprises people in “what does this print?” questions.
The diamond problem and language differences
If class D inherits from B and C, which both inherit from A and override the same method, which version does D get? C++ allows multiple inheritance and resolves it with virtual inheritance; Java and C# avoid it by allowing only single class inheritance but multiple interfaces (with default-method conflicts resolved explicitly); Python uses a method resolution order. Mentioning how your own language handles it shows real understanding. Language-specific detail is in our Java, C++ and Python guides.
Applying OOP in a design question
For “design a library system”, identify nouns (Book, Member, Loan, Librarian), give each a clear responsibility, use composition (a Library has Books), use an interface where behaviour varies (a FinePolicy), and keep state changes behind methods (Loan.return() computes fines). That small exercise is often the bridge to a full object-oriented design interview.
Practising
The fastest way to find gaps is to be asked. Run a spoken mock round on OOP topics — a free AI interview assistant such as CoPilot Interview builds one from your résumé and the job description and scores every answer — then study whatever you stumbled on. Prepare a ten-line code example for each pillar in your main language — writing it once fixes the definitions in memory.
Disclosure: CoPilot Interview is our product, so weigh what we say about it accordingly. Everything else on this page applies whichever tool you use, or none.
Frequently asked questions
What are the four pillars of OOP?
Encapsulation, abstraction, inheritance and polymorphism: bundling data with behaviour, hiding implementation details, reusing and extending classes, and using one interface with many implementations.
What is the difference between an interface and an abstract class?
An interface defines a contract a class can implement alongside others; an abstract class can include shared state and partial implementation but is usually limited to single inheritance.
Why is composition preferred over inheritance?
Composition builds behaviour from swappable parts and avoids the tight coupling and fragile hierarchies that deep inheritance creates.
What is runtime polymorphism?
When a call to an overridden method is resolved at runtime based on the actual object type, so a Shape reference calls the Circle or Square version as appropriate.
Practise on real interview questions
Run 145 real interview questions across 10 tracks, answer out loud and see a structured answer to compare with yours. Free, no signup.
Try a practice question