OOP Interview Questions and Answers (Object-Oriented Programming)
The OOP concepts every technical interview covers, explained simply.
Q1. Which OOP principle hides internal details and exposes only what's needed?
- A. Recursion
- B. Polymorphism
- C. Inheritance
- D. Encapsulation
Show answerHide answer
Answer: D. Encapsulation
Encapsulation bundles data with methods and restricts direct access.Q2. When a child class provides its own version of a parent's method, it is called:
- A. Encapsulation
- B. Method overriding
- C. Abstraction
- D. Method overloading
Show answerHide answer
Answer: B. Method overriding
Overriding replaces inherited behaviour; overloading is same name, different parameters.Q3. Polymorphism means:
- A. Copying objects
- B. The same interface behaves differently for different types
- C. A class having many attributes
- D. Using many modules
Show answerHide answer
Answer: B. The same interface behaves differently for different types
e.g. shape.area() works for Circle and Square, each with its own formula.Q4. An abstract class:
- A. Is the same as an interface in every language
- B. Cannot be inherited
- C. Cannot be instantiated directly and may have abstract methods
- D. Has no methods
Show answerHide answer
Answer: C. Cannot be instantiated directly and may have abstract methods
Subclasses must implement its abstract methods before objects can be created.Q5. Inheritance lets a class:
- A. Avoid constructors
- B. Hide its data
- C. Reuse and extend the behaviour of another class
- D. Run faster
Show answerHide answer
Answer: C. Reuse and extend the behaviour of another class
class Dog(Animal) gets Animal's attributes and methods.Q6. A constructor is:
- A. A static variable
- B. A special method called when an object is created
- C. A loop inside a class
- D. A method that deletes objects
Show answerHide answer
Answer: B. A special method called when an object is created
In Python it's __init__; in Java/C++ it has the class's name.Q7. What is an object?
- A. An instance of a class
- B. A function inside a module
- C. A blueprint for a class
- D. A type of loop
Show answerHide answer
Answer: A. An instance of a class
The class is the blueprint; objects are built from it.Q8. 'Composition over inheritance' suggests:
- A. Always inheriting from one base class
- B. Using only static methods
- C. Never using classes
- D. Building classes by combining objects rather than deep class hierarchies
Show answerHide answer
Answer: D. Building classes by combining objects rather than deep class hierarchies
A Car has an Engine, rather than Car being a kind of Engine.Q9. In Python, a name starting with a double underscore (e.g. __balance) triggers:
- A. A compile error
- B. Automatic encryption
- C. A global variable
- D. Name mangling, to discourage access from outside
Show answerHide answer
Answer: D. Name mangling, to discourage access from outside
It becomes _ClassName__balance, a convention for 'private'.Q10. Which is an example of method overloading (in languages like Java)?
- A. A class with two constructors in different files
- B. add(int, int) and add(double, double) in the same class
- C. A child class redefining speak()
- D. Calling super()
Show answerHide answer
Answer: B. add(int, int) and add(double, double) in the same class
Same method name, different parameter lists, in the same class.Q11. What does super() do in Python?
- A. Makes a method static
- B. Stops inheritance
- C. Calls a method from the parent class
- D. Creates a superclass
Show answerHide answer
Answer: C. Calls a method from the parent class
Commonly super().__init__(...) inside a child's constructor.Q12. A class method in Python receives which first argument?
- A. super
- B. cls (the class)
- C. self (the object)
- D. Nothing
Show answerHide answer
Answer: B. cls (the class)
@classmethod methods get the class; instance methods get self; @staticmethod gets neither.Q13. Which SOLID principle says a class should have only one reason to change?
- A. Open/Closed Principle
- B. Single Responsibility Principle
- C. Liskov Substitution Principle
- D. Dependency Inversion Principle
Show answerHide answer
Answer: B. Single Responsibility Principle
Each class should do one job well.Q14. The Open/Closed Principle says software entities should be:
- A. Open source and closed source
- B. Easy to open and close
- C. Public and private
- D. Open for extension, closed for modification
Show answerHide answer
Answer: D. Open for extension, closed for modification
Add new behaviour by extending, not by editing tested code.Q15. What is the diamond problem?
- A. An infinite loop in constructors
- B. Ambiguity when a class inherits from two classes that share a common parent
- C. A memory leak
- D. A sorting bug
Show answerHide answer
Answer: B. Ambiguity when a class inherits from two classes that share a common parent
Python resolves it with the Method Resolution Order (MRO).Q16. Which method controls what print(obj) shows in Python?
- A. __str__
- B. __call__
- C. __init__
- D. __len__
Show answerHide answer
Answer: A. __str__
__repr__ is the fallback and is meant for developers.Q17. An interface (as in Java) mainly defines:
- A. Method signatures a class promises to implement
- B. Database tables
- C. Private variables
- D. The main() method
Show answerHide answer
Answer: A. Method signatures a class promises to implement
It's a contract without (most) implementation.Q18. Which design pattern ensures a class has only one instance?
- A. Observer
- B. Factory
- C. Adapter
- D. Singleton
Show answerHide answer
Answer: D. Singleton
Used for things like a single configuration or logger object.Q19. The Observer pattern is used when:
- A. Many objects need to be notified when one object changes
- B. Only one object may exist
- C. Objects must be created in steps
- D. Two interfaces are incompatible
Show answerHide answer
Answer: A. Many objects need to be notified when one object changes
Like subscribing to notifications or event listeners.Q20. Abstraction in OOP means:
- A. Copying a class
- B. Deleting unused classes
- C. Writing abstract art
- D. Showing essential features while hiding implementation details
Show answerHide answer
Answer: D. Showing essential features while hiding implementation details
A user calls car.start() without knowing how the engine works.Q21. What are the four pillars of OOP?
- A. Classes, objects, methods, variables
- B. Loops, conditions, functions, arrays
- C. Encapsulation, abstraction, inheritance, polymorphism
- D. Compile, link, load, run
Show answerHide answer
Answer: C. Encapsulation, abstraction, inheritance, polymorphism
Be ready to give an example of each.Q22. What is an object?
- A. A data type like int
- B. A function inside a class
- C. A blueprint for classes
- D. An instance of a class
Show answerHide answer
Answer: D. An instance of a class
The class is the blueprint; objects are made from it.Q23. What is a constructor?
- A. A type of loop
- B. A static variable
- C. A method that deletes objects
- D. A special method that runs when an object is created
Show answerHide answer
Answer: D. A special method that runs when an object is created
It sets up the object's initial state.Q24. What is encapsulation?
- A. Writing many methods with the same name
- B. Inheriting from many classes
- C. Keeping data private and exposing it only through methods
- D. Hiding the class name
Show answerHide answer
Answer: C. Keeping data private and exposing it only through methods
e.g. a private balance with deposit() and withdraw().Q25. What is abstraction?
- A. Making all fields public
- B. Copying a class
- C. Creating many objects
- D. Showing only essential features and hiding implementation details
Show answerHide answer
Answer: D. Showing only essential features and hiding implementation details
You drive a car without knowing how the engine works.Q26. What is inheritance?
- A. Calling a method by name
- B. Creating objects from a class
- C. Hiding data
- D. A class acquiring the properties and methods of another class
Show answerHide answer
Answer: D. A class acquiring the properties and methods of another class
It models an 'is-a' relationship: a Car is a Vehicle.Q27. What is polymorphism?
- A. Many classes with one object
- B. Data hiding
- C. One interface, many implementations
- D. A class with many constructors only
Show answerHide answer
Answer: C. One interface, many implementations
e.g. shape.area() works for circles and squares.Q28. Method overriding happens when:
- A. A subclass provides its own version of a parent method with the same signature
- B. A method is declared static
- C. A method calls itself
- D. Two methods in one class share a name with different parameters
Show answerHide answer
Answer: A. A subclass provides its own version of a parent method with the same signature
Overriding is runtime polymorphism.Q29. Method overloading happens when:
- A. Methods in the same class share a name but have different parameters
- B. A child redefines a parent method
- C. A method is private
- D. A method has no return value
Show answerHide answer
Answer: A. Methods in the same class share a name but have different parameters
Overloading is compile-time polymorphism.Q30. What is an abstract class?
- A. A class that can't be inherited
- B. A class with no fields
- C. A class that can't be instantiated and may have abstract methods
- D. A class with only static methods
Show answerHide answer
Answer: C. A class that can't be instantiated and may have abstract methods
Subclasses fill in the abstract methods.Q31. What is an interface?
- A. A graphical screen
- B. A class with private constructors
- C. A list of variables
- D. A contract listing methods that implementing classes must provide
Show answerHide answer
Answer: D. A contract listing methods that implementing classes must provide
A class can implement many interfaces.Q32. What is the difference between composition and inheritance?
- A. Composition is 'has-a'; inheritance is 'is-a'
- B. Composition is 'is-a'; inheritance is 'has-a'
- C. They are the same
- D. Composition only works with interfaces
Show answerHide answer
Answer: A. Composition is 'has-a'; inheritance is 'is-a'
A Car has an Engine (composition); a Car is a Vehicle (inheritance).Q33. Why is composition often preferred over inheritance?
- A. It is more flexible and avoids tight coupling to a parent class
- B. It uses less memory always
- C. It is faster to compile
- D. Inheritance is not allowed in most languages
Show answerHide answer
Answer: A. It is more flexible and avoids tight coupling to a parent class
'Favour composition over inheritance' is a classic design principle.Q34. What does the 'super' (or base) keyword do?
- A. Ends the program
- B. Makes a method static
- C. Refers to the parent class, e.g. to call its constructor or method
- D. Creates a new object
Show answerHide answer
Answer: C. Refers to the parent class, e.g. to call its constructor or method
super(...) must be the first line of a Java constructor.Q35. What is a static method?
- A. A method that belongs to the class, not to any object
- B. A method that can't return values
- C. A private method
- D. A method that never changes
Show answerHide answer
Answer: A. A method that belongs to the class, not to any object
Call it as ClassName.method().Q36. What is a destructor?
- A. A method that deletes a class
- B. A static method
- C. A method that runs when an object is destroyed, to free resources
- D. A method that creates objects
Show answerHide answer
Answer: C. A method that runs when an object is destroyed, to free resources
C++ has destructors; Java relies on garbage collection instead.Q37. What does 'is-a' relationship mean in OOP?
- A. An object containing another object
- B. Two unrelated classes
- C. Inheritance between a subclass and a superclass
- D. A method call
Show answerHide answer
Answer: C. Inheritance between a subclass and a superclass
A Dog is an Animal.Q38. What is multiple inheritance?
- A. Many methods in a class
- B. A class inheriting from more than one parent class
- C. Many objects of one class
- D. A chain of single inheritance
Show answerHide answer
Answer: B. A class inheriting from more than one parent class
C++ supports it; Java allows it only through interfaces.Q39. What is the diamond problem?
- A. Ambiguity when a class inherits the same member from two parents that share a base
- B. A sorting bug
- C. A deadlock between threads
- D. A memory leak in trees
Show answerHide answer
Answer: A. Ambiguity when a class inherits the same member from two parents that share a base
C++ solves it with virtual inheritance; Java avoids it by disallowing multiple class inheritance.Q40. What is coupling in software design?
- A. How much one class depends on another
- B. How fast two classes run together
- C. How many methods a class has
- D. The number of objects created
Show answerHide answer
Answer: A. How much one class depends on another
Aim for low coupling.Q41. What is cohesion in a class?
- A. How long its methods are
- B. How many objects it creates
- C. How many classes it inherits
- D. How closely its responsibilities belong together
Show answerHide answer
Answer: D. How closely its responsibilities belong together
Aim for high cohesion: one class, one job.Q42. What does the Single Responsibility Principle say?
- A. A class should have one method
- B. Each method should have one line
- C. A program should have one class
- D. A class should have only one reason to change
Show answerHide answer
Answer: D. A class should have only one reason to change
The S in SOLID.Q43. What does the Open/Closed Principle say?
- A. Classes should be open for extension but closed for modification
- B. Methods should be open to all callers
- C. Files should be closed after use
- D. Classes should be public
Show answerHide answer
Answer: A. Classes should be open for extension but closed for modification
Add behaviour with new classes instead of editing working code.Q44. What does the Liskov Substitution Principle say?
- A. Subclasses must have more methods
- B. Parents must be abstract
- C. Objects of a subclass should be usable wherever the parent is expected
- D. Only one subclass is allowed
Show answerHide answer
Answer: C. Objects of a subclass should be usable wherever the parent is expected
If a Square breaks code expecting a Rectangle, the design is wrong.Q45. What does the Dependency Inversion Principle say?
- A. Low-level modules should call high-level ones
- B. Depend on abstractions, not on concrete classes
- C. Inherit from as many classes as possible
- D. Avoid all dependencies
Show answerHide answer
Answer: B. Depend on abstractions, not on concrete classes
e.g. depend on a PaymentGateway interface, not on RazorpayClient directly.Q46. What is the Singleton design pattern?
- A. A class that allows only one instance
- B. A class with one field
- C. A function that runs once
- D. A class with one method
Show answerHide answer
Answer: A. A class that allows only one instance
Often used for configuration or logging.Q47. What is the Factory design pattern?
- A. A class that destroys objects
- B. A method or class that creates objects without exposing the exact class
- C. A pattern for sorting
- D. A loop that creates many objects
Show answerHide answer
Answer: B. A method or class that creates objects without exposing the exact class
e.g. ShapeFactory.create("circle").Q48. What is the Observer pattern?
- A. A way to copy objects
- B. One object watches the CPU
- C. Objects subscribe to be notified when another object changes
- D. A pattern for debugging
Show answerHide answer
Answer: C. Objects subscribe to be notified when another object changes
Used for event listeners and notifications.Q49. What is a getter and setter?
- A. Constructors
- B. Methods to create and delete objects
- C. Methods to read and update a private field
- D. Loops over a list
Show answerHide answer
Answer: C. Methods to read and update a private field
They let a class validate changes to its data.Q50. What is an instance variable?
- A. A variable that belongs to each object separately
- B. A constant
- C. A variable shared by all objects
- D. A local variable in a method
Show answerHide answer
Answer: A. A variable that belongs to each object separately
Each object has its own copy; static variables are shared.Q51. Can a constructor be private?
- A. No, never
- B. Only in interfaces
- C. Only in abstract classes
- D. Yes, e.g. to implement a singleton
Show answerHide answer
Answer: D. Yes, e.g. to implement a singleton
Then objects are created through a static method.Q52. What is dynamic (late) binding?
- A. Assigning values to variables
- B. Creating objects in a loop
- C. Deciding which overridden method to call at run time
- D. Linking libraries at compile time
Show answerHide answer
Answer: C. Deciding which overridden method to call at run time
This is what makes runtime polymorphism work.Q53. What is an access modifier?
- A. A type of loop
- B. A keyword that controls who can use a class member
- C. A compiler flag
- D. A function that changes values
Show answerHide answer
Answer: B. A keyword that controls who can use a class member
public, private, protected (and default/package in Java).Q54. What is the purpose of the final (Java) / sealed (C#) keyword on a class?
- A. To prevent the class from being inherited
- B. To allow multiple inheritance
- C. To make it abstract
- D. To make all methods static
Show answerHide answer
Answer: A. To prevent the class from being inherited
String in Java is final.Q55. What is a copy constructor?
- A. A static constructor
- B. A constructor that creates an object as a copy of another object of the same class
- C. A constructor with no parameters
- D. A constructor that deletes objects
Show answerHide answer
Answer: B. A constructor that creates an object as a copy of another object of the same class
Common in C++: ClassName(const ClassName& other).Q56. What is the difference between a shallow and a deep copy?
- A. A shallow copy copies nothing
- B. There is no difference
- C. A shallow copy shares nested objects; a deep copy duplicates them too
- D. A deep copy is faster
Show answerHide answer
Answer: C. A shallow copy shares nested objects; a deep copy duplicates them too
Changing a nested list in a shallow copy affects the original.Q57. What is association in OOP?
- A. A class inheriting another
- B. A general relationship where objects use each other
- C. A static method
- D. A private field
Show answerHide answer
Answer: B. A general relationship where objects use each other
Aggregation and composition are special kinds of association.Q58. In aggregation, what happens to the part when the whole is destroyed?
- A. The part becomes static
- B. The part can live on independently
- C. The program crashes
- D. The part is always destroyed
Show answerHide answer
Answer: B. The part can live on independently
A Department has Teachers, but teachers exist without it. In composition, parts die with the whole.Q59. What is a virtual function table (vtable)?
- A. A table of variables in memory
- B. A table of function pointers used to call overridden methods at run time
- C. A database table
- D. A list of classes in a program
Show answerHide answer
Answer: B. A table of function pointers used to call overridden methods at run time
Each class with virtual functions has one.Q60. Which OOP concept is shown by a Shape reference holding a Circle object?
- A. Composition
- B. Encapsulation
- C. Overloading
- D. Polymorphism
Show answerHide answer
Answer: D. Polymorphism
The reference type is general; the object is specific.
Practised these? Now prove it.
Take a timed mock test with new questions every attempt, earn a verified certificate at 70%+, and get noticed by employers.
Start a mock test