OOP Interview Questions and Answers (Object-Oriented Programming)

The OOP concepts every technical interview covers, explained simply.

  1. Q1. Which OOP principle hides internal details and exposes only what's needed?

    • A. Recursion
    • B. Polymorphism
    • C. Inheritance
    • D. Encapsulation
    Show answer

    Answer: D. Encapsulation
    Encapsulation bundles data with methods and restricts direct access.

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

    Answer: B. Method overriding
    Overriding replaces inherited behaviour; overloading is same name, different parameters.

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

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

    Answer: C. Cannot be instantiated directly and may have abstract methods
    Subclasses must implement its abstract methods before objects can be created.

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

    Answer: C. Reuse and extend the behaviour of another class
    class Dog(Animal) gets Animal's attributes and methods.

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

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

    Answer: A. An instance of a class
    The class is the blueprint; objects are built from it.

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

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

    Answer: D. Name mangling, to discourage access from outside
    It becomes _ClassName__balance, a convention for 'private'.

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

    Answer: B. add(int, int) and add(double, double) in the same class
    Same method name, different parameter lists, in the same class.

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

    Answer: C. Calls a method from the parent class
    Commonly super().__init__(...) inside a child's constructor.

  12. Q12. A class method in Python receives which first argument?

    • A. super
    • B. cls (the class)
    • C. self (the object)
    • D. Nothing
    Show answer

    Answer: B. cls (the class)
    @classmethod methods get the class; instance methods get self; @staticmethod gets neither.

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

    Answer: B. Single Responsibility Principle
    Each class should do one job well.

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

    Answer: D. Open for extension, closed for modification
    Add new behaviour by extending, not by editing tested code.

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

  16. Q16. Which method controls what print(obj) shows in Python?

    • A. __str__
    • B. __call__
    • C. __init__
    • D. __len__
    Show answer

    Answer: A. __str__
    __repr__ is the fallback and is meant for developers.

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

    Answer: A. Method signatures a class promises to implement
    It's a contract without (most) implementation.

  18. Q18. Which design pattern ensures a class has only one instance?

    • A. Observer
    • B. Factory
    • C. Adapter
    • D. Singleton
    Show answer

    Answer: D. Singleton
    Used for things like a single configuration or logger object.

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

    Answer: A. Many objects need to be notified when one object changes
    Like subscribing to notifications or event listeners.

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

    Answer: D. Showing essential features while hiding implementation details
    A user calls car.start() without knowing how the engine works.

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

    Answer: C. Encapsulation, abstraction, inheritance, polymorphism
    Be ready to give an example of each.

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

    Answer: D. An instance of a class
    The class is the blueprint; objects are made from it.

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

    Answer: D. A special method that runs when an object is created
    It sets up the object's initial state.

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

    Answer: C. Keeping data private and exposing it only through methods
    e.g. a private balance with deposit() and withdraw().

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

    Answer: D. Showing only essential features and hiding implementation details
    You drive a car without knowing how the engine works.

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

    Answer: D. A class acquiring the properties and methods of another class
    It models an 'is-a' relationship: a Car is a Vehicle.

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

    Answer: C. One interface, many implementations
    e.g. shape.area() works for circles and squares.

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

    Answer: A. A subclass provides its own version of a parent method with the same signature
    Overriding is runtime polymorphism.

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

    Answer: A. Methods in the same class share a name but have different parameters
    Overloading is compile-time polymorphism.

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

    Answer: C. A class that can't be instantiated and may have abstract methods
    Subclasses fill in the abstract methods.

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

    Answer: D. A contract listing methods that implementing classes must provide
    A class can implement many interfaces.

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

    Answer: A. Composition is 'has-a'; inheritance is 'is-a'
    A Car has an Engine (composition); a Car is a Vehicle (inheritance).

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

    Answer: A. It is more flexible and avoids tight coupling to a parent class
    'Favour composition over inheritance' is a classic design principle.

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

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

    Answer: A. A method that belongs to the class, not to any object
    Call it as ClassName.method().

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

    Answer: C. A method that runs when an object is destroyed, to free resources
    C++ has destructors; Java relies on garbage collection instead.

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

    Answer: C. Inheritance between a subclass and a superclass
    A Dog is an Animal.

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

    Answer: B. A class inheriting from more than one parent class
    C++ supports it; Java allows it only through interfaces.

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

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

    Answer: A. How much one class depends on another
    Aim for low coupling.

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

    Answer: D. How closely its responsibilities belong together
    Aim for high cohesion: one class, one job.

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

    Answer: D. A class should have only one reason to change
    The S in SOLID.

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

    Answer: A. Classes should be open for extension but closed for modification
    Add behaviour with new classes instead of editing working code.

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

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

    Answer: B. Depend on abstractions, not on concrete classes
    e.g. depend on a PaymentGateway interface, not on RazorpayClient directly.

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

    Answer: A. A class that allows only one instance
    Often used for configuration or logging.

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

    Answer: B. A method or class that creates objects without exposing the exact class
    e.g. ShapeFactory.create("circle").

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

    Answer: C. Objects subscribe to be notified when another object changes
    Used for event listeners and notifications.

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

    Answer: C. Methods to read and update a private field
    They let a class validate changes to its data.

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

    Answer: A. A variable that belongs to each object separately
    Each object has its own copy; static variables are shared.

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

    Answer: D. Yes, e.g. to implement a singleton
    Then objects are created through a static method.

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

    Answer: C. Deciding which overridden method to call at run time
    This is what makes runtime polymorphism work.

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

    Answer: B. A keyword that controls who can use a class member
    public, private, protected (and default/package in Java).

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

    Answer: A. To prevent the class from being inherited
    String in Java is final.

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

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

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

    Answer: B. A general relationship where objects use each other
    Aggregation and composition are special kinds of association.

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

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

    Answer: B. A table of function pointers used to call overridden methods at run time
    Each class with virtual functions has one.

  60. Q60. Which OOP concept is shown by a Shape reference holding a Circle object?

    • A. Composition
    • B. Encapsulation
    • C. Overloading
    • D. Polymorphism
    Show 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