# OOPs Interview Questions: 72 Questions Across 18 Topics

> OOPs interview questions grouped by topic: 72 questions from 18 OOP notes on inheritance, polymorphism and C++ keywords.

Canonical: https://devsunite.com/resources/core-subjects/oop
Last updated: 2026-11-22

Object-oriented programming fundamentals: inheritance, polymorphism, and the keywords/principles that come up in every C++/Java interview.

18 topics across 4 categories, 72 interview questions

## Top 10 OOP interview questions with answers

1. **What's the difference between compile-time and runtime polymorphism?** Compile-time polymorphism (like function overloading) is resolved by the compiler before the program runs; runtime polymorphism (like method overriding via virtual functions) is resolved while the program is executing, based on the object's actual type. [Overview of Polymorphism](https://devsunite.com/resources/core-subjects/oop/overview-of-polymorphism)
2. **What problem does inheritance actually solve?** Code reuse and modeling real "is-a" relationships, so shared behavior lives in one place instead of being duplicated. [Overview of Inheritance](https://devsunite.com/resources/core-subjects/oop/overview-of-inheritance)
3. **Why doesn't Java support multiple inheritance of classes?** To avoid the diamond problem, the ambiguity that arises when a class inherits the same member from two different paths. Java sidesteps it by only allowing multiple inheritance through interfaces, which don't carry implementation ambiguity in the same way. [Types of Inheritance](https://devsunite.com/resources/core-subjects/oop/types-of-inheritance)
4. **What is the diamond problem?** When a class inherits the same base class through two or more separate paths, creating duplicate, ambiguous copies of that base class's members. [Virtual Base Classes](https://devsunite.com/resources/core-subjects/oop/virtual-base-classes)
5. **What's required for a method to properly override a superclass method?** The exact same method name, parameter list, and return type (or a covariant subtype of the return type), and it can't reduce the method's accessibility (can't override a public method with a private one). [Method Overriding](https://devsunite.com/resources/core-subjects/oop/method-overriding)
6. **Can two functions be overloads if they only differ by return type?** No, the parameter list itself must differ, the compiler resolves overloads based on the arguments in the call, and return type alone isn't part of that resolution. [Function Overloading](https://devsunite.com/resources/core-subjects/oop/function-overloading)
7. **What makes a class abstract in C++?** Having at least one pure virtual function, a virtual function declared with = 0 and no implementation. [Abstract Classes and Pure Virtual Functions](https://devsunite.com/resources/core-subjects/oop/abstract-classes-and-pure-virtual-functions)
8. **What's the actual difference between composition and aggregation?** Ownership and lifecycle: composition means the contained object's lifetime is tied to the container (it can't outlive it); aggregation means the objects have independent lifetimes. [Composition vs Aggregation vs Inheritance](https://devsunite.com/resources/core-subjects/oop/composition-vs-aggregation-vs-inheritance)
9. **Explain the Single Responsibility Principle with an example.** A class that handles both saving user data to a database and formatting it for an email report has two reasons to change (a database schema change, or an email format change), violating SRP, it should be split into two focused classes. [SOLID Principles](https://devsunite.com/resources/core-subjects/oop/solid-principles)
10. **Can a static method access non-static (instance) members?** No, not directly, a static method has no specific object to refer to, so it can only call other static members unless it's given a specific instance to work with as a parameter. [The static Keyword](https://devsunite.com/resources/core-subjects/oop/static-keyword)

## Inheritance

- [Overview of Inheritance](https://devsunite.com/resources/core-subjects/oop/overview-of-inheritance) - Inheritance lets one class acquire the properties and behavior of another, so common logic lives in one place instead of being copied across every related class.
- [Super and Sub Classes](https://devsunite.com/resources/core-subjects/oop/super-and-sub-classes) - The superclass is the general, shared class being inherited from; the subclass is the specific class that inherits from it and can extend or override its behavior.
- [Types of Inheritance](https://devsunite.com/resources/core-subjects/oop/types-of-inheritance) - Inheritance comes in five structural shapes: single, multilevel, hierarchical, multiple, and hybrid, each describing a different arrangement of base and derived classes.
- [Access Specifiers in Inheritance](https://devsunite.com/resources/core-subjects/oop/access-specifiers-in-inheritance) - Public, protected, and private inheritance in C++ each change how much of the base class's interface the derived class exposes to the outside world.
- [Constructor and Destructor Order in Inheritance](https://devsunite.com/resources/core-subjects/oop/constructor-and-destructor-in-inheritance) - When an object of a derived class is created, base class constructors run first and derived constructors run last; destruction happens in exactly the reverse order.
- [Virtual Base Classes](https://devsunite.com/resources/core-subjects/oop/virtual-base-classes) - Virtual base classes solve the diamond problem in multiple inheritance by ensuring only one shared copy of a common ancestor's members exists, instead of one copy per inheritance path.
- [Composition vs Aggregation vs Inheritance](https://devsunite.com/resources/core-subjects/oop/composition-vs-aggregation-vs-inheritance) - Inheritance models is-a relationships, composition models strong has-a ownership where the parts can't outlive the whole, and aggregation models loose has-a relationships where they can.

## Keywords

- [The static Keyword](https://devsunite.com/resources/core-subjects/oop/static-keyword) - static changes a variable or method's lifetime and scope: a static class member is shared across every instance instead of belonging to just one.
- [The this Keyword](https://devsunite.com/resources/core-subjects/oop/this-keyword) - this is a reference to the current object, the specific instance a method is currently running on, used to resolve naming conflicts and enable method chaining.
- [The const Keyword](https://devsunite.com/resources/core-subjects/oop/const-keyword) - const marks a variable, method, or parameter as unmodifiable, letting the compiler catch accidental changes and communicate intent directly in the code.
- [The final Keyword](https://devsunite.com/resources/core-subjects/oop/final-keyword) - final in Java (or its C++ equivalent) stops a variable from being reassigned, a method from being overridden, or a class from being extended at all.

## Misc

- [Smart Pointers](https://devsunite.com/resources/core-subjects/oop/smart-pointers) - Smart pointers automatically manage the lifetime of dynamically allocated memory, freeing it exactly when it's no longer needed so you don't have to call delete by hand.
- [SOLID Principles](https://devsunite.com/resources/core-subjects/oop/solid-principles) - SOLID is a set of five object-oriented design principles, Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, and Dependency Inversion, aimed at making code easier to change safely.

## Polymorphism

- [Overview of Polymorphism](https://devsunite.com/resources/core-subjects/oop/overview-of-polymorphism) - Polymorphism lets the same method call behave differently depending on the actual object it's invoked on, letting code work with a family of related types through one shared interface.
- [Function Overloading](https://devsunite.com/resources/core-subjects/oop/function-overloading) - Function overloading lets multiple functions share the same name as long as their parameter lists differ, letting the compiler pick the right one based on the arguments used.
- [Method Overriding](https://devsunite.com/resources/core-subjects/oop/method-overriding) - Method overriding lets a subclass provide its own implementation of a method already defined in its superclass, with the actual version called determined at runtime by the object's real type.
- [Virtual Functions and Inline Virtual Functions](https://devsunite.com/resources/core-subjects/oop/virtual-functions-and-inline-virtual-functions) - A virtual function tells the compiler to resolve which version to call at runtime based on the object's real type, which is exactly what makes overriding and polymorphism work in C++.
- [Abstract Classes and Pure Virtual Functions](https://devsunite.com/resources/core-subjects/oop/abstract-classes-and-pure-virtual-functions) - An abstract class cannot be instantiated directly and exists purely to define a shared interface, with pure virtual functions forcing every concrete subclass to provide its own implementation.

## All 72 OOP interview questions

### Inheritance

- [Overview of Inheritance](https://devsunite.com/resources/core-subjects/oop/overview-of-inheritance)

1. What problem does inheritance actually solve?
2. What's the difference between inheritance and composition?
3. Can a derived class access private members of the base class?
4. What happens if you don't call the base class constructor explicitly?

- [Super and Sub Classes](https://devsunite.com/resources/core-subjects/oop/super-and-sub-classes)

1. Can a subclass have multiple superclasses?
2. Does a subclass inherit private fields?
3. Can you have an instance of just the superclass?
4. If a subclass overrides a method, can it still call the superclass's version?

- [Types of Inheritance](https://devsunite.com/resources/core-subjects/oop/types-of-inheritance)

1. Why doesn't Java support multiple inheritance of classes?
2. What's the difference between hierarchical and multilevel inheritance?
3. Give an example of hybrid inheritance.
4. Does C++ allow multiple inheritance, and what's the risk?

- [Access Specifiers in Inheritance](https://devsunite.com/resources/core-subjects/oop/access-specifiers-in-inheritance)

1. What's the default inheritance mode in C++ for `class`, and for `struct`?
2. Can a derived class access a private member of its base class?
3. When would you use private inheritance instead of composition?
4. Does Java have the equivalent of protected or private inheritance?

- [Constructor and Destructor Order in Inheritance](https://devsunite.com/resources/core-subjects/oop/constructor-and-destructor-in-inheritance)

1. In what order do constructors run in an inheritance chain?
2. In what order do destructors run?
3. What happens if you don't explicitly call a base class constructor?
4. Why does a polymorphic base class need a virtual destructor?

- [Virtual Base Classes](https://devsunite.com/resources/core-subjects/oop/virtual-base-classes)

1. What is the diamond problem?
2. How do you fix the diamond problem in C++?
3. Why doesn't Java have this problem?
4. Does virtual inheritance have any cost?

- [Composition vs Aggregation vs Inheritance](https://devsunite.com/resources/core-subjects/oop/composition-vs-aggregation-vs-inheritance)

1. What's the actual difference between composition and aggregation?
2. Why is 'favor composition over inheritance' such common advice?
3. Give a real example of when inheritance is still the right choice.
4. How would you model a 'Car has an Engine' relationship, and why not inheritance?

### Keywords

- [The static Keyword](https://devsunite.com/resources/core-subjects/oop/static-keyword)

1. Can a static method access non-static (instance) members?
2. What's the difference between a static and non-static variable?
3. Can you override a static method?
4. Give a real use case for a static variable.

- [The this Keyword](https://devsunite.com/resources/core-subjects/oop/this-keyword)

1. Why is `this` needed when a parameter has the same name as a field?
2. Is `this` available in a static method?
3. How does returning `this` enable method chaining?
4. What does `this()` (as a call, not just a reference) do inside a constructor in Java?

- [The const Keyword](https://devsunite.com/resources/core-subjects/oop/const-keyword)

1. What does marking a member function `const` actually guarantee?
2. Why pass a parameter as `const&` instead of by value?
3. Can a const method call a non-const method on the same object?
4. Is `const` the same as Java's `final`?

- [The final Keyword](https://devsunite.com/resources/core-subjects/oop/final-keyword)

1. What are the three things `final` can apply to in Java, and what does each do?
2. Why would you mark a class as `final`?
3. Does `final` mean the object itself is immutable?
4. How does `final` help with thread safety?

### Misc

- [Smart Pointers](https://devsunite.com/resources/core-subjects/oop/smart-pointers)

1. What's the difference between `unique_ptr` and `shared_ptr`?
2. When would you use `weak_ptr`?
3. What problem do smart pointers actually solve?
4. Is there overhead to using `shared_ptr` compared to a raw pointer?

- [SOLID Principles](https://devsunite.com/resources/core-subjects/oop/solid-principles)

1. Explain the Single Responsibility Principle with an example.
2. What does Open/Closed actually mean in practice?
3. Give a real, common violation of Liskov Substitution.
4. Why is Dependency Inversion useful for testing?

### Polymorphism

- [Overview of Polymorphism](https://devsunite.com/resources/core-subjects/oop/overview-of-polymorphism)

1. What's the difference between compile-time and runtime polymorphism?
2. How does runtime polymorphism actually work under the hood?
3. Why is polymorphism useful?
4. Give a real example of polymorphism you've used or seen.

- [Function Overloading](https://devsunite.com/resources/core-subjects/oop/function-overloading)

1. Can two functions be overloads if they only differ by return type?
2. Is function overloading resolved at compile time or runtime?
3. What happens if a call matches more than one overload ambiguously?
4. How is overloading different from overriding?

- [Method Overriding](https://devsunite.com/resources/core-subjects/oop/method-overriding)

1. What's required for a method to properly override a superclass method?
2. What does `@Override` (or `override` in C++) actually do?
3. Can you call the superclass's version of an overridden method?
4. What's the difference between overriding and hiding a static method?

- [Virtual Functions and Inline Virtual Functions](https://devsunite.com/resources/core-subjects/oop/virtual-functions-and-inline-virtual-functions)

1. What happens if you don't mark a base class method as `virtual` and a derived class defines the same method?
2. How does a vtable work?
3. Is there a performance cost to virtual functions?
4. What is a pure virtual function?

- [Abstract Classes and Pure Virtual Functions](https://devsunite.com/resources/core-subjects/oop/abstract-classes-and-pure-virtual-functions)

1. What makes a class abstract in C++?
2. Can an abstract class have a constructor?
3. Can a pure virtual function have an implementation?
4. What's the difference between an abstract class and a regular class with all virtual methods overridden by default?

## Frequently asked questions

### Where do these oops interview questions come from?

Each of the 72 questions comes from the "What interviewers actually ask" section of one of 18 OOP topic notes. Every question links to its topic page, where it is answered next to the explanation it tests.

### What does the OOP section cover?

18 topics across 4 categories: Object-oriented programming fundamentals: inheritance, polymorphism, and the keywords/principles that come up in every C++/Java interview.

### Is it free to read?

Yes. Every article is free to read with no account required. Creating a free DevsUnite account lets you mark topics as read and track your progress across every Core Subjects article.

## Related

- [Operating Systems](https://devsunite.com/resources/core-subjects/operating-systems)
- [DBMS](https://devsunite.com/resources/core-subjects/dbms)
- [Computer Networks](https://devsunite.com/resources/core-subjects/computer-networks)
- [Core Subjects](https://devsunite.com/resources/core-subjects)
