Top 50 OOPs Interview Questions & Answers
The definitive technical question bank asked at Google, Amazon, Microsoft, and Uber. Arranged section-wise with both rapid-revision summaries and deep-dive architectural solutions.
Mock tests for SSC, Banking, Railways, UPSC & state exams
Real exam pattern, negative marking and a worked solution for every question.
What is Object Oriented Programming (OOPs)?
A programming paradigm based on the concept of "objects" that bundle state (data) and behavior (methods) together.
| 1 | // C++ Object-Oriented representation |
| 2 | #include <iostream> |
| 3 | #include <string> |
| 4 | |
| 5 | class BankAccount { |
| 6 | private: |
| 7 | double balance; // Data (State) |
| 8 | public: |
| 9 | BankAccount(double initial) : balance(initial) {} |
| 10 | |
| 11 | void deposit(double amount) { // Method (Behavior) |
| 12 | if (amount > 0) balance += amount; |
| 13 | } |
| 14 | double getBalance() const { return balance; } |
| 15 | }; |
What are the main advantages of using OOPs?
Modularity, code reusability, easy maintenance, data abstraction, bottom-up design, and polymorphism flexibility.
What is a Class?
A user-defined data type and blueprint/template containing data members and member functions.
What is an Object?
An instance of a class that represents a real-world entity with state and behavior.
Explain the 4 Pillars of OOPs.
Encapsulation, Data Abstraction, Polymorphism, and Inheritance.
What is Encapsulation?
Bundling data and methods into a single class (data binding) and restricting unauthorized access (data hiding).
What is Abstraction?
Displaying only essential functionality to the user while hiding internal implementation details.
Explain Polymorphism and its types.
"Many forms" — allowing code to behave differently depending on runtime context or signatures.
Explain Inheritance.
Mechanism where a child class acquires properties and behaviors from a parent class for code reuse.
What are the various types of Inheritance?
Single, Multiple, Multilevel, Hierarchical, and Hybrid inheritance.
Practise placement aptitude on the real test pattern
TCS NQT, Infosys, Wipro, Accenture and Cognizant style mocks with section-wise analysis.
What is the difference between a class and an object?
A class is a conceptual blueprint (template), while an object is a concrete, physical instance in memory.
What are access specifiers and what is the inheritance visibility matrix?
Keywords (public, protected, private) that govern member visibility across classes and inheritance.
What is the difference between Method Overloading and Method Overriding?
Overloading = same name, different parameters (compile-time). Overriding = same signature in subclass (runtime).
What is a Subclass (Child Class)?
A class that derives from and inherits properties and behaviors of another class.
What is a Superclass (Parent Class)?
A class whose features and methods are inherited by subclasses.
What is a Constructor?
A special member method with the same name as the class, invoked automatically to initialize new objects.
What are the various types of constructors in C++ / Java?
Default constructor, Non-parameterized constructor, Parameterized constructor, and Copy constructor.
What is a Destructor?
A method automatically invoked when an object goes out of scope or is deleted, releasing resources.
Can we overload a constructor in a class?
Yes! Constructor overloading is standard across Java, C++, and C#.
Can we overload a destructor in a class?
No! There can only be exactly one destructor in a class.
Read without ads with TestMeMan Pro
Ad-free articles plus timed mock tests with worked solutions.
What is meant by Garbage Collection in the OOP world?
Automatic background memory management that frees heap memory allocated to unreachable objects.
What are the characteristics of an abstract class?
Cannot be instantiated, must be inherited, can contain both abstract and concrete methods, always public.
What is Constructor Chaining?
Invoking one constructor from another constructor within the same class or parent class hierarchy.
Name the operators in C++ that CANNOT be overloaded.
Scope resolution (::), Ternary (? :), Member dot (.), Pointer-to-member (.*), and sizeof.
What are the types of variables in OOP?
Instance variables (object-level/heap), Static variables (class-level), Local variables (method-level/stack), and Reference variables.
Is it always necessary to create objects from a class to use its methods?
No, static methods can be called directly using the class name without instantiating an object.
What is a Virtual Function?
A member function declared in a base class and overridden in a derived class to enable runtime polymorphism.
What is a Pure Virtual Function?
A virtual function with no implementation in the base class, making the class abstract (syntax: = 0).
Explain the static keyword in depth (functions, variables, blocks).
Associates members with the class itself rather than instances, creating shared state and early initialization.
What is the difference between a Class and a Structure?
Classes combine data + behavior and support OOP (private by default in C++). Structures primarily group plain data (public by default).
Read without ads with TestMeMan Pro
Ad-free articles plus timed mock tests with worked solutions.
Can you create an object of an abstract class directly?
No, abstract classes cannot be instantiated directly with the "new" operator.
What is the super keyword used for?
Refers to the immediate parent class object to call superclass constructors or overridden methods.
What is the difference between == and .equals() in Java?
== tests reference equality (same memory address). .equals() tests logical content/value equality.
What is a private constructor, and when is it used?
A constructor with private access; used to prevent external instantiation, most notably in Singleton classes.
What is the difference between static and instance methods?
Static methods belong to the class (no "this"). Instance methods belong to an object instance and can access instance state.
What is the final keyword used for in Java?
Prevents modification: constants for variables, prevents overriding for methods, prevents inheritance for classes.
What is the difference between Composition and Inheritance?
Inheritance is an "is-a" relationship (Car is a Vehicle). Composition is a "has-a" relationship (Car has an Engine).
What is a Singleton class and how do you implement it?
A class that restricts instantiation to a single global instance with a private constructor.
What is the this keyword used for?
A reference to the current object instance within a method or constructor.
What is the difference between an Interface and an Abstract Class?
Interfaces define contracts and allow multiple inheritance. Abstract classes provide partial implementations and shared state.
Read without ads with TestMeMan Pro
Ad-free articles plus timed mock tests with worked solutions.
What is the difference between Shallow Copy and Deep Copy?
Shallow copy copies references to nested objects. Deep copy creates independent clones of all nested objects.
What is a Static Block and when is it executed?
A static initialization block executed once when the class is first loaded into memory by the classloader.
What is the Diamond Problem in Inheritance?
Ambiguity arising in multiple inheritance when a class inherits from two parent classes that share a common ancestor.
What is the purpose of the finalize() method?
A cleanup method called by the Garbage Collector prior to object memory reclamation (now deprecated in modern Java).
What is Method Hiding?
When a subclass defines a static method with the exact same signature as a static method in its superclass.
What is a Marker Interface?
An interface with no methods or constants used to tag/mark a class for special JVM or framework handling.
What is the difference between instanceof and getClass()?
instanceof checks if an object is an instance of a class OR any subclass. getClass() checks the exact runtime class.
What is the purpose of the volatile keyword?
Guarantees that reads and writes to a variable go directly to main memory, preventing thread caching issues.
What is the difference between ArrayList and LinkedList?
ArrayList is backed by a dynamic array (O(1) random access). LinkedList is a doubly-linked list (O(1) insert/delete).
What is the transient keyword used for?
Marks an instance variable so that it is skipped and not serialized into a byte stream during object serialization.
Hiring? Screen candidates with a skills test
Role-based assessments for sales, support, accounts, analyst and fresher roles.