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.
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