If you are preparing for a software placement drive, an SDE role, or a service-company interview, OOPs interview questions are almost guaranteed to show up. Object-Oriented Programming (OOP) is the foundation of Java, C++, Python, C#, and most modern back-end stacks, which is exactly why campus recruiters and hiring panels lean on it so heavily in the first technical round. This 2026 guide brings together 45+ of the most commonly asked OOPs interview questions and answers, organized by topic, with short correct explanations and small code snippets in Java, C++, and Python.
The goal here is completeness. Most lists cover the four pillars and stop there. This guide goes deeper into SOLID principles, association versus aggregation versus composition, output-prediction questions, and the language-specific traps that interviewers in India spring during placement rounds. Whether you are a fresher heading into your first TCS, Infosys, Wipro, or Accenture drive or an experienced engineer targeting a product company, work through these in order and you will cover the ground that matters.
OOP Basics
1. What is Object-Oriented Programming (OOP)?
OOP is a programming paradigm that structures software around objects rather than functions and logic. An object bundles together data (attributes) and behaviour (methods) that operate on that data. Programs are then designed as a collection of objects that interact with each other. The four core pillars are encapsulation, abstraction, inheritance, and polymorphism.
2. Why do we need OOP? What problems does it solve?
Before OOP, procedural programming spread data and functions across a program with little structure, which made large codebases hard to maintain and reuse. OOP solves this by:
- Modelling real-world entities directly as objects, making code intuitive.
- Improving reusability through inheritance and composition.
- Hiding internal complexity through encapsulation and abstraction.
- Making code easier to extend and maintain as requirements grow.
3. What are the main features of OOP?
The four fundamental features (pillars) are encapsulation, abstraction, inheritance, and polymorphism. Supporting concepts include classes, objects, message passing, and dynamic binding.
4. Which are the major object-oriented programming languages?
Java, C++, C#, Python, Ruby, Kotlin, Swift, and PHP are widely used OOP languages. Note that some, like Python and C++, are multi-paradigm and support procedural and functional styles as well.
5. How does OOP differ from procedural (structured) programming?
| Aspect | Procedural Programming | Object-Oriented Programming |
|---|---|---|
| Basic unit | Function / procedure | Object |
| Data handling | Data and functions are separate | Data and functions bundled in objects |
| Data access | Often global, exposed | Controlled via access modifiers |
| Reusability | Limited | High (inheritance, composition) |
| Approach | Top-down | Bottom-up |
| Examples | C, Pascal | Java, C++, Python |
6. What are the advantages and disadvantages of OOP?
Advantages: modularity, reusability, easier maintenance, data security through encapsulation, and a natural mapping to real-world problems. Disadvantages: it can add design overhead for small programs, has a steeper learning curve, and poorly designed inheritance hierarchies can become rigid and hard to change.
Class vs Object
7. What is a class?
A class is a blueprint or template that defines the attributes (data) and methods (behaviour) common to a type of object. It does not occupy memory for its data members until an object is created.
8. What is an object?
An object is an instance of a class. It is a concrete entity created from the blueprint, and it occupies memory. If Car is a class, then myCar created from it is an object with its own state.
class Car {
String model;
void drive() { System.out.println(model + " is driving"); }
}
Car myCar = new Car(); // object created
myCar.model = "Nexon";
myCar.drive();
9. What is the difference between a class and an object?
A class is a logical definition and does not consume memory for state; an object is a physical instance that exists in memory at runtime. One class can produce many objects, each with its own independent state.
10. What is the difference between a structure and a class (C++)?
| Feature | Structure | Class |
|---|---|---|
| Default access | public | private |
| Typical use | Plain data grouping | Data plus behaviour |
| Inheritance default | public | private |
| OOP support | Limited by convention | Full |
In modern C++ both can hold methods; the practical difference is the default access specifier. In C, structures cannot hold methods at all.
The Four Pillars of OOP
Encapsulation
11. What is encapsulation?
Encapsulation is the bundling of data and the methods that operate on that data into a single unit (a class), while restricting direct access to the internal state. It is often called data hiding. Access is controlled through access modifiers and exposed through getters and setters.
class Account {
private double balance; // hidden
public double getBalance() { return balance; }
public void deposit(double amt) {
if (amt > 0) balance += amt; // controlled write
}
}
12. Why is encapsulation important?
It protects an object's internal state from unintended external modification, allows validation logic inside setters, and lets you change the internal implementation without breaking code that uses the class.
13. What is the difference between abstraction and encapsulation?
Abstraction is about hiding complexity and exposing only what is relevant (the "what"). Encapsulation is about bundling data with methods and restricting access (the "how it is protected"). Abstraction is a design-level concern; encapsulation is an implementation-level mechanism that supports it.
Abstraction
14. What is abstraction?
Abstraction means hiding implementation details and exposing only the essential features of an object. A user of a List calls add() without knowing whether it is backed by an array or a linked structure. In code, abstraction is achieved using abstract classes and interfaces.
15. How is abstraction achieved in Java and C++?
In Java, through abstract classes and interfaces. In C++, through abstract classes containing pure virtual functions. In Python, through the abc module and abstract base classes.
from abc import ABC, abstractmethod
class Shape(ABC):
@abstractmethod
def area(self): ...
class Circle(Shape):
def __init__(self, r): self.r = r
def area(self): return 3.14 * self.r * self.r
Inheritance
16. What is inheritance?
Inheritance lets a class (child/derived/subclass) acquire the attributes and methods of another class (parent/base/superclass). It promotes code reuse and establishes an "is-a" relationship. A Dog is an Animal, so Dog inherits from Animal.
class Animal { void eat() { System.out.println("eating"); } }
class Dog extends Animal { void bark() { System.out.println("barking"); } }
17. What is the difference between a superclass and a subclass?
A superclass (base/parent) is the class being inherited from. A subclass (derived/child) inherits from it and can add or override behaviour.
18. What are the limitations of inheritance?
Deep inheritance hierarchies increase coupling, make code harder to follow, and can break subclasses when the parent changes (the fragile base class problem). Overusing inheritance where composition would fit better leads to rigid designs. This is why the guideline "favour composition over inheritance" exists.
Polymorphism
19. What is polymorphism?
Polymorphism means "many forms." It allows the same interface or method name to behave differently based on context or object type. The two categories are compile-time (static) and runtime (dynamic) polymorphism.
20. What is the difference between compile-time and runtime polymorphism?
| Aspect | Compile-time (Static) | Runtime (Dynamic) |
|---|---|---|
| Achieved by | Method overloading, operator overloading | Method overriding |
| Binding | Early (compile time) | Late (runtime) |
| Resolution | By signature | By actual object type |
| Flexibility | Lower | Higher |
| Speed | Faster | Slight dispatch overhead |
21. How is runtime polymorphism implemented internally?
Through dynamic dispatch. In C++ this uses a virtual table (vtable) and virtual pointer per object; the correct overridden method is looked up at runtime. In Java, all non-static, non-final methods are virtual by default, and the JVM resolves the actual method based on the object's runtime type.
Animal a = new Dog(); // reference type Animal, object type Dog
a.sound(); // calls Dog's sound() at runtime
Method Overloading vs Overriding
22. What is method overloading?
Method overloading means having multiple methods with the same name but different parameter lists (number, type, or order of parameters) within the same class. It is resolved at compile time.
int add(int a, int b) { return a + b; }
double add(double a, double b) { return a + b; }
23. What is method overriding?
Method overriding means a subclass provides its own implementation of a method already defined in its superclass, with the same signature. It is resolved at runtime and enables dynamic polymorphism.
24. What is the difference between overloading and overriding?
| Aspect | Overloading | Overriding |
|---|---|---|
| Definition | Same name, different parameters | Same name and signature in subclass |
| Scope | Within one class | Across parent and child classes |
| Polymorphism type | Compile-time | Runtime |
| Return type | Can differ | Must be same or covariant |
| Inheritance needed | No | Yes |
25. Can we override a static method?
No. Static methods belong to the class, not to instances, so they are not polymorphic. If you declare a static method with the same signature in a subclass, it is method hiding, not overriding, and resolution happens at compile time based on the reference type.
26. Can constructors be overloaded? Can they be overridden?
Constructors can be overloaded (multiple constructors with different parameter lists). Constructors cannot be inherited, so they cannot be overridden.
Constructors and Destructors
27. What is a constructor?
A constructor is a special method that runs automatically when an object is created, used to initialize the object's state. It has the same name as the class and no return type.
28. What are the types of constructors?
- Default constructor: no parameters, provided by the compiler if none is defined.
- Parameterized constructor: takes arguments to initialize fields.
- Copy constructor: creates a new object as a copy of an existing one (common in C++).
class Point {
int x, y;
public:
Point() : x(0), y(0) {} // default
Point(int a, int b) : x(a), y(b) {} // parameterized
Point(const Point &p) : x(p.x), y(p.y) {} // copy
};
29. What is a destructor?
A destructor is a special method that runs when an object is destroyed, used to release resources (memory, file handles, connections). In C++ it is written as ~ClassName(). Java and Python do not have explicit destructors; they rely on garbage collection, though Python offers __del__ and Java historically had finalize() (now deprecated).
30. What is a virtual destructor and why is it needed (C++)?
When you delete a derived object through a base-class pointer, a non-virtual destructor calls only the base destructor, leaking the derived part. Declaring the base destructor virtual ensures the full destructor chain runs, preventing resource leaks.
31. What is garbage collection?
Garbage collection is automatic memory management that reclaims memory occupied by objects no longer reachable by the program. Java and Python handle this automatically, freeing developers from manual delete, though objects with unclosed external resources still need explicit cleanup.
Types of Inheritance
32. What are the types of inheritance?
- Single: one subclass inherits from one superclass.
- Multilevel: a chain, A to B to C.
- Hierarchical: multiple subclasses inherit from one superclass.
- Multiple: one subclass inherits from more than one superclass.
- Hybrid: a combination of two or more of the above.
33. Does Java support multiple inheritance? Why or why not?
Java does not support multiple inheritance of classes, to avoid the diamond problem and ambiguity. It does support multiple inheritance of type through interfaces, since a class can implement many interfaces.
34. What is the diamond problem?
The diamond problem occurs in multiple inheritance when two parent classes inherit from a common ancestor and a child inherits from both. If both parents override the same method, the child faces ambiguity about which version to use. C++ resolves this with virtual inheritance; Java avoids it by disallowing multiple class inheritance; Python resolves it using the Method Resolution Order (MRO).
35. What is Method Resolution Order (MRO) in Python?
MRO is the order in which Python searches base classes when resolving a method or attribute. Python uses the C3 linearization algorithm. You can inspect it with ClassName.__mro__ or ClassName.mro().
Abstract Class vs Interface
36. What is an abstract class?
An abstract class is a class that cannot be instantiated and is meant to be subclassed. It can have both abstract methods (without a body) and concrete methods (with implementation), plus constructors and instance fields.
37. What is an interface?
An interface is a contract that specifies method signatures a class must implement. In classic Java it contains only abstract method declarations and constants; since Java 8 it can also have default and static methods.
38. What is the difference between an abstract class and an interface?
| Aspect | Abstract Class | Interface |
|---|---|---|
| Methods | Abstract and concrete | Abstract (plus default/static in Java 8+) |
| Fields | Instance fields allowed | Constants only (public static final) |
| Constructor | Yes | No |
| Multiple inheritance | Not supported (single parent) | Supported (implement many) |
| Access modifiers | Any | Methods implicitly public |
| Use case | Shared base with common code | Pure capability/contract |
39. When should you use an abstract class versus an interface?
Use an abstract class when related classes share common code and state (an "is-a" relationship with shared implementation). Use an interface to define a capability that unrelated classes can implement (a "can-do" relationship), or when a class needs multiple type inheritance.
40. What is a pure virtual function (C++)?
A pure virtual function is declared with = 0 and has no implementation in the base class, for example virtual void draw() = 0;. A class with at least one pure virtual function becomes abstract and cannot be instantiated. This is C++'s way of creating interfaces.
Access Modifiers
41. What are access modifiers?
Access modifiers control the visibility and accessibility of classes, methods, and variables, enforcing encapsulation. The common ones in Java are:
| Modifier | Same class | Same package | Subclass | Anywhere |
|---|---|---|---|---|
| private | Yes | No | No | No |
| default (no keyword) | Yes | Yes | No | No |
| protected | Yes | Yes | Yes | No |
| public | Yes | Yes | Yes | Yes |
In C++, the specifiers are private, protected, and public. Python has no strict enforcement; it uses naming conventions (a leading underscore for "protected by convention" and a double underscore for name mangling).
42. What is the difference between private and protected?
A private member is accessible only within its own class. A protected member is also accessible in subclasses (and, in Java, within the same package), which makes it useful for exposing internals to derived classes without making them fully public.
Association, Aggregation, and Composition
43. What is association?
Association is a general relationship where objects of one class are connected to objects of another, without ownership. For example, a Teacher is associated with a Student. It can be one-to-one, one-to-many, or many-to-many.
44. What is aggregation?
Aggregation is a specialized "has-a" association representing a whole-part relationship where the part can exist independently of the whole. A Department has Professors, but professors continue to exist even if the department is dissolved. It is a weak ownership.
45. What is composition?
Composition is a stronger "has-a" relationship where the part cannot exist without the whole. A House is composed of Rooms; if the house is destroyed, the rooms cease to exist. It represents strong ownership and lifecycle dependency.
| Aspect | Association | Aggregation | Composition |
|---|---|---|---|
| Relationship | Uses | Has-a (weak) | Has-a (strong) |
| Ownership | None | Weak | Strong |
| Lifecycle | Independent | Independent | Dependent |
| Example | Teacher and Student | Department and Professor | House and Room |
46. Why is composition often preferred over inheritance?
Composition gives more flexibility because behaviour can be changed at runtime by swapping components, avoids the fragile base class problem, and does not force a rigid hierarchy. Inheritance tightly couples the child to the parent's implementation, so many designs favour composition for maintainability.
SOLID Principles
Product companies and experienced-level interviews frequently probe SOLID, so understand each letter with an example.
47. What are the SOLID principles?
SOLID is a set of five design principles for writing maintainable, extensible object-oriented code, introduced by Robert C. Martin:
- S, Single Responsibility Principle: a class should have only one reason to change, meaning one responsibility. A class that both parses data and writes to a database violates this.
- O, Open/Closed Principle: software entities should be open for extension but closed for modification. Add new behaviour by adding new code (for example, a new subclass or strategy), not by editing existing tested code.
- L, Liskov Substitution Principle: objects of a subclass should be replaceable for objects of the superclass without breaking correctness. If
SquareextendsRectanglebut breaks the width/height contract, it violates LSP. - I, Interface Segregation Principle: clients should not be forced to depend on methods they do not use. Prefer several small, specific interfaces over one large general-purpose interface.
- D, Dependency Inversion Principle: high-level modules should depend on abstractions, not on concrete low-level modules. Depend on an interface like
PaymentGateway, not on a concreteRazorpayClient.
48. How does SOLID improve code quality?
Following SOLID reduces coupling, increases cohesion, and makes code easier to test, extend, and refactor. It reduces the ripple effect of changes and is a common differentiator between junior and senior candidates in system-design-adjacent interview rounds.
Common Code and Output Questions
Output-prediction questions test whether you truly understand binding, initialization order, and dispatch. These are frequent in on-campus and off-campus coding rounds.
49. What is the output of this overriding example (Java)?
class A { void show() { System.out.println("A"); } }
class B extends A { void show() { System.out.println("B"); } }
A obj = new B();
obj.show();
Output: B. Even though the reference type is A, the method called is decided at runtime by the actual object type B. This is dynamic dispatch.
50. What is the output of this static hiding example (Java)?
class A { static void show() { System.out.println("A"); } }
class B extends A { static void show() { System.out.println("B"); } }
A obj = new B();
obj.show();
Output: A. Static methods are not polymorphic. Resolution is based on the reference type A at compile time (method hiding, not overriding).
51. What is the order of execution: static block, instance block, constructor (Java)?
Static blocks run first (once, when the class loads), then for each object the instance initializer blocks run, then the constructor body. If there is inheritance, the parent's static block runs before the child's static block, and the parent constructor runs before the child constructor.
52. What does this overloading resolution print?
void print(int x) { System.out.println("int"); }
void print(double x) { System.out.println("double"); }
print('A'); // char
Output: int. There is no char overload, so 'A' is promoted to int (the nearest wider type) before double, so the int version wins.
53. Constructor chaining: what runs first, parent or child constructor?
The parent constructor runs first. When you create a child object, the constructor implicitly calls super() (or you can call it explicitly) before executing the child's own constructor body, ensuring the base part is initialized first.
Related Concepts Interviewers Ask
54. What are friend functions and friend classes (C++)?
A friend function or class can access the private and protected members of another class. It is declared with the friend keyword and deliberately breaks encapsulation for tightly-coupled scenarios such as operator overloading. Use it sparingly.
55. What is the difference between shallow copy and deep copy?
A shallow copy copies field values, so reference fields still point to the same underlying objects (shared state). A deep copy duplicates the referenced objects too, producing a fully independent copy. This matters when objects hold collections or nested objects.
56. What is the difference between a virtual function and a pure virtual function (C++)?
A virtual function has a default implementation in the base class that derived classes may override. A pure virtual function has no implementation and forces derived classes to provide one, making the base class abstract.
57. What is dynamic binding?
Dynamic binding (late binding) links a method call to its implementation at runtime rather than compile time, based on the actual object type. It is the mechanism behind runtime polymorphism.
How to Prepare for OOPs Interviews
OOPs rounds reward clear fundamentals plus the ability to explain trade-offs out loud. Here is a practical plan:
-
Master the four pillars with your own examples. Do not memorize textbook lines. Be ready to explain encapsulation using a bank account, inheritance using a vehicle hierarchy, and so on. Interviewers can tell rote answers from understood ones.
-
Pick one primary language and know its specifics. Java candidates should know interfaces,
final, and method hiding. C++ candidates should know vtables, virtual destructors, and virtual inheritance. Python candidates should know MRO, duck typing, and theabcmodule. -
Practice output-prediction questions. Static versus instance binding, initialization order, and overload resolution catch many candidates off guard. Trace them on paper.
-
Connect OOP to design. For experienced roles, be ready to apply SOLID, composition over inheritance, and association/aggregation/composition to a small design prompt.
-
Do timed mock interviews. Reading answers is not the same as speaking them under pressure. A structured session with the Goodspace AI Mock Interview gives you role-specific OOPs questions, real-time follow-ups, and feedback on how clearly you explained each concept, which mirrors an actual placement round.
-
Revise the tables. The overloading-versus-overriding and abstract-class-versus-interface comparisons are asked in almost every drive.
For freshers walking into TCS, Infosys, Wipro, Accenture, Capgemini, or Cognizant drives, the questions skew toward definitions, the four pillars, inheritance types, and simple output questions. For experienced engineers targeting product companies, expect SOLID, design trade-offs, and deeper language internals. When you want to simulate the real thing end to end, a full AI-powered mock interview with instant feedback is one of the fastest ways to find and close your weak spots before the real panel does.
Frequently Asked Questions (FAQ)
Q1. Are OOPs questions asked in every software interview?
For most Java, C++, C#, and Python roles, yes, OOPs concepts appear in the first technical round, especially in Indian service-company placement drives and fresher hiring. Even for roles that lean functional, interviewers often check whether you understand encapsulation and abstraction.
Q2. Which OOPs topics are most important for freshers?
The four pillars (encapsulation, abstraction, inheritance, polymorphism), class versus object, constructors, types of inheritance, overloading versus overriding, and abstract class versus interface. These cover the bulk of fresher-level questions.
Q3. What extra OOPs topics do experienced candidates need?
SOLID principles, association versus aggregation versus composition, composition over inheritance, design patterns, and language internals like vtables (C++) or MRO (Python). Experienced rounds test judgement and design reasoning, not just definitions.
Q4. Should I prepare OOPs in a specific programming language?
Prepare in the language listed on your resume or in the job description, because interviewers ask language-specific follow-ups. Understanding the underlying concepts helps you answer regardless of language, but be fluent in at least one.
Q5. Is memorizing answers enough to clear an OOPs round?
No. Interviewers probe with follow-up questions and code examples. Understanding why a concept exists, and being able to give your own example, is far more effective than memorizing definitions.
Q6. How many OOPs questions should I practise before an interview?
Working through 40 to 50 solid questions covering all the pillars, comparisons, and a handful of output questions gives good coverage. Then reinforce with two or three timed mock interviews so you can explain each concept confidently under pressure.
Final Word
OOPs is one of the highest-return topics you can prepare, because the same concepts recur across nearly every software interview and across languages. Work through these 45+ questions until you can explain each one in your own words, keep the comparison tables handy for revision, and practise the output questions until the binding rules feel automatic. Combine that with a few realistic mock interviews, and you will walk into your next OOPs round ready for whatever the panel asks.






