OOPs Interview Questions
OOPs (object-oriented programming) concepts come up in almost every software and developer interview. These are the questions interviewers actually ask, with concise answers you can speak confidently.
17 questions with concise, interview-ready answers.
1. What is Object-Oriented Programming (OOP)?
OOP is a programming paradigm that organizes software around objects — self-contained units that bundle data (attributes) and behavior (methods) together. Instead of writing procedures that act on loose data, you model real-world entities as objects that interact. Its four core pillars are encapsulation, abstraction, inheritance, and polymorphism.
2. What is a class and what is an object?
A class is a blueprint or template that defines the attributes and methods a type of object will have. An object is a concrete instance of that class, created at runtime, with its own actual values for those attributes. For example, "Car" is a class, while a specific red Toyota is an object of that class.
3. What is encapsulation?
Encapsulation is bundling data and the methods that operate on it inside a single unit (a class) and restricting direct access to the internal state. It is achieved by making fields private and exposing controlled access through public getters and setters. This protects an object's data from accidental or invalid modification and is often called data hiding.
4. What is abstraction?
Abstraction means hiding complex implementation details and exposing only the essential features of an object to the user. It lets you focus on what an object does rather than how it does it. In code it is achieved using abstract classes and interfaces — for example, you call a car's start() method without needing to know the engine internals.
5. What is inheritance?
Inheritance lets one class (the child or subclass) acquire the attributes and methods of another class (the parent or superclass). It promotes code reuse and establishes an "is-a" relationship — a Dog is an Animal. The child class can use the parent's members and also add or override its own behavior.
6. What is polymorphism?
Polymorphism means "many forms" — the ability of the same operation or method name to behave differently depending on the object or context. It comes in two types: compile-time (method overloading) and runtime (method overriding). It lets you write flexible code that works with objects of different types through a common interface.
7. What is the difference between compile-time and runtime polymorphism?
Compile-time polymorphism (method overloading) is resolved by the compiler based on the method signature — same method name with different parameter lists. Runtime polymorphism (method overriding) is resolved at runtime through dynamic dispatch, where a subclass provides its own implementation of a parent method and the actual object type decides which runs. Overloading is static binding; overriding is dynamic binding.
8. What is the difference between method overloading and method overriding?
Overloading defines multiple methods with the same name but different parameters within the same class, and is resolved at compile time. Overriding redefines a parent class method in a subclass with the same signature, and is resolved at runtime. Overloading changes the parameter list; overriding keeps the signature identical but changes the implementation.
9. What is the difference between abstraction and encapsulation?
Abstraction is about hiding complexity — exposing only what an object does and hiding how it does it, solved at the design level using abstract classes and interfaces. Encapsulation is about hiding data — wrapping data and methods together and restricting access, solved at the implementation level using access modifiers. In short, abstraction hides complexity while encapsulation hides data.
10. What is the difference between an interface and an abstract class?
An abstract class can have both abstract and concrete methods, instance fields, and constructors, and a class can extend only one. An interface traditionally declares only method signatures (a pure contract), supports multiple inheritance, and its fields are constants. Use an abstract class to share common code among closely related classes, and an interface to define a capability that unrelated classes can implement.
11. What are the types of inheritance?
The common types are single (one child, one parent), multilevel (a chain such as A to B to C), hierarchical (multiple children share one parent), and multiple (one child inherits from several parents). Multiple inheritance of classes is restricted in languages like Java and C# due to the diamond problem, though it is supported through interfaces.
12. What is the difference between association, aggregation, and composition?
Association is a general relationship where objects know about each other (a Teacher and a Student). Aggregation is a weaker "has-a" relationship where the part can exist independently of the whole — a Department has Professors, but professors survive if the department closes. Composition is a stronger "has-a" where the part cannot exist without the whole — a House has Rooms, and the rooms cease to exist if the house is destroyed.
13. What is a constructor and what are its types?
A constructor is a special method that runs automatically when an object is created, used to initialize its state, and it shares the name of the class with no return type. Common types are the default (no-argument) constructor, the parameterized constructor that takes arguments, and the copy constructor that creates a new object from an existing one. If you write no constructor, the compiler provides a default one.
14. What is the difference between this and super?
The "this" keyword refers to the current object instance and is used to access the current class's members or call another constructor of the same class. The "super" keyword refers to the immediate parent class and is used to access the parent's methods, fields, or constructor. In short, "this" points to the current class while "super" points to the superclass.
15. What are the SOLID principles?
SOLID is a set of five design principles for maintainable object-oriented code: 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 types), Interface Segregation (prefer many specific interfaces over one general one), and Dependency Inversion (depend on abstractions, not concrete implementations).
16. What are the rules for method overriding?
The overriding method must have the same name, parameter list, and a compatible return type as the parent method. It cannot reduce the access level of the overridden method (it can widen it), and it cannot throw broader checked exceptions. Static, final, and private methods cannot be overridden, and the method must be inherited to be overridden.
17. Why is multiple inheritance restricted in languages like Java?
Multiple inheritance of classes is restricted mainly to avoid the diamond problem — when a class inherits from two parents that both define the same method, the compiler cannot decide which version to use, causing ambiguity. Java avoids this by allowing a class to extend only one class while still implementing multiple interfaces, which keeps the inheritance hierarchy unambiguous and simpler to maintain.
Get these answered live in your real interview
NostrobeAI is a real-time AI interview copilot — it hears the question and drafts a strong answer on your screen, invisible on Zoom, Meet, and Teams. One-time pricing, no subscription.
Try NostrobeAI free