HomeSubjectsUniversityBlogAbout

Object-Oriented Programming (OOP)

Topic in Programming

210 total MCQsShowing 30 with explanations10 Easy10 Medium10 Hard

About This Topic

Object-oriented programming is a paradigm that organises software around objects, which bundle data as attributes with the methods that operate on that data. Questions revolve around the four pillars: encapsulation, abstraction, inheritance and polymorphism. You should define classes, objects, constructors, getters and setters, and access modifiers, and contrast overloading with overriding and abstract classes with interfaces. Expect multiple inheritance and the diamond problem, association versus aggregation versus composition, and the Liskov Substitution Principle among the SOLID rules. Some items also cover dependency injection and patterns built on objects, such as the Visitor and Specification patterns.

Below are 30 practice questions from a pool of 210 Object-Oriented Programming (OOP) MCQs, one of 16 topics in Programming. Each shows the correct answer with an explanation; when you are ready, take a timed quiz to test recall under exam conditions.

Practice Questions

Each question below shows the correct answer with a full explanation. Use these to build conceptual understanding before attempting a timed quiz.

Object-Oriented Programming (OOP)Easy

Q1. What is the 'new' keyword used for?

  1. A.Deleting an existing object from memory
  2. B.Declaring a new variable in the scope
  3. C.Defining a new method in the class
  4. D.Creating a new instance of a class✓ Correct

Explanation

The 'new' keyword allocates memory and creates a new instance of a class by invoking its constructor.

Report an error in this question

Object-Oriented Programming (OOP)Easy

Q2. What is a class in OOP?

  1. A.A variable type for storing data
  2. B.A blueprint for creating objects✓ Correct
  3. C.A loop construct for iteration
  4. D.A reusable function for operations

Explanation

A class defines the structure (attributes) and behavior (methods) that its objects will have.

Report an error in this question

Object-Oriented Programming (OOP)Easy

Q3. What is encapsulation?

  1. A.Inheriting properties from a parent class definition
  2. B.A sorting method that orders elements in a collection
  3. C.A type of iterative loop control structure in code
  4. D.Bundling data and methods while restricting direct access✓ Correct

Explanation

Encapsulation bundles data and methods together while hiding internal details, controlling access through public interfaces.

Report an error in this question

Object-Oriented Programming (OOP)Easy

Q4. What is a constructor?

  1. A.A static method belonging to the class itself
  2. B.A getter method that returns a field value
  3. C.A destructor that cleans up object state
  4. D.A special method called when creating an object✓ Correct

Explanation

A constructor is automatically invoked when a new object is instantiated, used to set up initial values.

Report an error in this question

Object-Oriented Programming (OOP)Easy

Q5. What is an object in OOP?

  1. A.A standalone function
  2. B.A class definition in code
  3. C.A primitive data type
  4. D.An instance of a class✓ Correct

Explanation

An object is a concrete instance of a class, with its own state and behavior.

Report an error in this question

Object-Oriented Programming (OOP)Easy

Q6. What is inheritance in OOP?

  1. A.Acquiring properties and methods from a parent class✓ Correct
  2. B.Creating a new object instance from a class
  3. C.A form of encapsulation that hides internal details
  4. D.A design pattern for structuring application code

Explanation

Inheritance allows a child class to reuse fields and methods of a parent class, promoting code reuse.

Report an error in this question

Object-Oriented Programming (OOP)Easy

Q7. What does the 'this' keyword refer to?

  1. A.The current object instance✓ Correct
  2. B.A static method reference
  3. C.The class definition itself
  4. D.The parent class reference

Explanation

'this' refers to the current object instance, used to access its own fields and methods within the class.

Report an error in this question

Object-Oriented Programming (OOP)Easy

Q8. What is an access modifier?

  1. A.A keyword controlling member visibility level✓ Correct
  2. B.A data type for storing numeric values only
  3. C.A type of loop construct in the language
  4. D.A constructor for initializing object state

Explanation

Access modifiers like public, private, and protected control which parts of the program can access a class's members.

Report an error in this question

Object-Oriented Programming (OOP)Easy

Q9. What is a method in OOP?

  1. A.A standalone function not tied to any class
  2. B.A function defined inside a class for objects✓ Correct
  3. C.A variable that stores data in the program
  4. D.A data type that defines value constraints

Explanation

A method is a function associated with a class that defines behavior and can access the object's attributes.

Report an error in this question

Object-Oriented Programming (OOP)Medium

Q10. What is an interface?

  1. A.A class with full method implementations provided
  2. B.A contract defining method signatures without bodies✓ Correct
  3. C.An abstract class with some methods implemented
  4. D.A type of variable for storing object references

Explanation

An interface defines a set of method signatures without implementation; classes implementing the interface must provide the method bodies.

Report an error in this question

Object-Oriented Programming (OOP)Easy

Q11. What is polymorphism?

  1. A.A class relationship defined by inheritance hierarchy
  2. B.A type of encapsulation hiding internal data details
  3. C.Different objects responding differently to same method✓ Correct
  4. D.Having only one single form of behavior always

Explanation

Polymorphism allows objects of different classes to be treated uniformly through a common interface while each provides its own implementation.

Report an error in this question

Object-Oriented Programming (OOP)Medium

Q12. What is the difference between method overloading and method overriding?

  1. A.They are the same concept with different names in different languages
  2. B.Overloading requires an inheritance hierarchy between the classes involved
  3. C.Overriding changes the method parameter list in the parent class definition
  4. D.Overloading: same name different params; overriding: same signature in subclass✓ Correct

Explanation

Overloading defines multiple methods with the same name but different parameters; overriding redefines a parent's method with the same signature in a subclass.

Report an error in this question

Object-Oriented Programming (OOP)Medium

Q13. What is a static method?

  1. A.A method belonging to the class not any specific instance✓ Correct
  2. B.A constructor method for initializing new object state
  3. C.A method that can never be overridden by subclasses
  4. D.A private method accessible only within the same class

Explanation

A static method belongs to the class itself, not to instances, and can be invoked without creating an object.

Report an error in this question

Object-Oriented Programming (OOP)Medium

Q14. What is the super keyword?

  1. A.A global variable accessible everywhere in code
  2. B.A reference to parent class for calling its members✓ Correct
  3. C.The main class that serves as program entry point
  4. D.A type of access modifier restricting member access

Explanation

'super' refers to the parent class and is used to call the parent's constructor, methods, or access parent fields.

Report an error in this question

Object-Oriented Programming (OOP)Medium

Q15. What is the difference between composition and inheritance?

  1. A.Composition is always slower than inheritance in performance
  2. B.Inheritance is an is-a relationship; composition is has-a✓ Correct
  3. C.They are exactly the same concept with no difference at all
  4. D.Inheritance is more flexible and loosely coupled overall

Explanation

Inheritance creates an 'is-a' relationship; composition creates a 'has-a' relationship, generally offering more flexibility.

Report an error in this question

Object-Oriented Programming (OOP)Medium

Q16. What are getter and setter methods?

  1. A.Static methods belonging to the class directly
  2. B.Methods for controlled field read and write access✓ Correct
  3. C.Loop constructs for iterating over collections
  4. D.Constructor types for initializing objects

Explanation

Getters return the value of private fields; setters allow controlled modification, enforcing encapsulation.

Report an error in this question

Object-Oriented Programming (OOP)Medium

Q17. What is an abstract class?

  1. A.A fully implemented class with all methods defined
  2. B.A static class that only contains class-level members
  3. C.A final class that cannot be extended by other classes
  4. D.A class that cannot be instantiated with abstract methods✓ Correct

Explanation

An abstract class cannot be instantiated directly and may contain abstract methods that concrete subclasses must override.

Report an error in this question

Object-Oriented Programming (OOP)Hard

Q18. What is the SOLID principle in OOP?

  1. A.A coding style guide for naming conventions in code
  2. B.A data structure for organizing elements efficiently
  3. C.Five design principles: SRP, OCP, LSP, ISP, and DIP✓ Correct
  4. D.A testing framework for validating software behavior

Explanation

SOLID comprises five principles for creating maintainable OOP software: SRP, OCP, LSP, ISP, and DIP.

Report an error in this question

Object-Oriented Programming (OOP)Hard

Q19. What is a mixin?

  1. A.A class that mixes different data types together randomly
  2. B.A class providing methods to others without being standalone✓ Correct
  3. C.A type of interface that defines a strict method contract
  4. D.A structural design pattern for building complex objects

Explanation

A mixin provides reusable methods to other classes via multiple inheritance or similar mechanisms, without being intended for standalone instantiation.

Report an error in this question

Object-Oriented Programming (OOP)Hard

Q20. What is the object slicing problem in C++?

  1. A.Splitting an object into smaller component parts for storage
  2. B.When assigning derived to base variable, derived data is lost✓ Correct
  3. C.A memory allocation issue caused by fragmented heap storage
  4. D.A threading problem from concurrent access to shared objects

Explanation

Object slicing occurs when a derived class object is copied to a base class variable by value, losing the derived class's additional data members.

Report an error in this question

Object-Oriented Programming (OOP)Medium

Q21. What is the Liskov Substitution Principle (LSP)?

  1. A.A design pattern for constructing complex object hierarchies
  2. B.A principle for sorting elements in a collection efficiently
  3. C.A rule for managing memory allocation in large applications
  4. D.Subclass objects should be substitutable for superclass objects✓ Correct

Explanation

LSP states that subclass objects must be substitutable for their parent class objects without altering the desirable properties of the program.

Report an error in this question

Object-Oriented Programming (OOP)Hard

Q22. What is a virtual method table (vtable)?

  1. A.A hash table for caching method results quickly
  2. B.A debug table for tracking method execution and logging
  3. C.A lookup table for resolving dynamic method calls at runtime✓ Correct
  4. D.A method list defined in the source code of the program

Explanation

A vtable is a compiler-generated table of function pointers used at runtime to resolve virtual method calls.

Report an error in this question

Object-Oriented Programming (OOP)Hard

Q23. What is the fragile base class problem?

  1. A.A compilation error from missing method implementations
  2. B.A memory leak caused by improper object disposal code
  3. C.A class that is too small to be useful on its own
  4. D.Base class changes can break derived classes unexpectedly✓ Correct

Explanation

The fragile base class problem occurs when modifications to a base class unintentionally break subclasses.

Report an error in this question

Object-Oriented Programming (OOP)Medium

Q24. What is the diamond problem?

  1. A.An error related to geometric shapes in rendering code
  2. B.A memory leak issue caused by circular object references only
  3. C.An ambiguity when inheriting from classes with common ancestor✓ Correct
  4. D.A compilation warning about unused variables in the program

Explanation

The diamond problem occurs when class D inherits from B and C, both inheriting from A, creating ambiguity about which version of A's members D should use.

Report an error in this question

Object-Oriented Programming (OOP)Hard

Q25. What is the difference between prototype-based and class-based OOP?

  1. A.Prototype-based OOP is always slower than class-based OOP overall
  2. B.Class-based uses blueprints; prototype-based clones existing objects✓ Correct
  3. C.They are the same approach with no meaningful differences at all
  4. D.Class-based OOP cannot support any form of inheritance at all

Explanation

Class-based OOP creates objects from class blueprints; prototype-based OOP creates objects by cloning prototypes and using delegation chains.

Report an error in this question

Object-Oriented Programming (OOP)Medium

Q26. What is multiple inheritance and which languages support it?

  1. A.Creating multiple instances of the same class simultaneously
  2. B.Inheriting from a single parent class in a linear hierarchy
  3. C.Inheriting from multiple parents; supported by C++ and Python✓ Correct
  4. D.All programming languages support this feature universally

Explanation

Multiple inheritance allows a class to inherit from more than one parent. C++ and Python support it; Java uses interfaces instead.

Report an error in this question

Object-Oriented Programming (OOP)Hard

Q27. What is the difference between association, aggregation, and composition?

  1. A.Association is general; aggregation weak; composition strong ownership✓ Correct
  2. B.They are all identical concepts with just different names used
  3. C.Composition is always the better design choice in every single case
  4. D.Only naming differences exist with no behavioral distinctions at all

Explanation

Association is a loose relationship; aggregation implies ownership but parts can exist independently; composition implies the part's lifecycle depends on the whole.

Report an error in this question

Object-Oriented Programming (OOP)Hard

Q28. What is covariant return type?

  1. A.A generic type parameter used in collection class definitions
  2. B.Allowing an overriding method to return a more specific subtype✓ Correct
  3. C.Always returning the exact same type as the parent declares
  4. D.A type error that occurs when return types do not match up

Explanation

Covariant return types allow an overriding method to narrow the return type to a subtype of the original.

Report an error in this question

Object-Oriented Programming (OOP)Hard

Q29. What is double dispatch and how does it differ from single dispatch?

  1. A.Single dispatch uses two methods while double dispatch uses only one
  2. B.There is no practical difference between the two dispatch mechanisms
  3. C.Single dispatch selects by one type; double dispatch by two types✓ Correct
  4. D.Double dispatch is twice as fast in execution as single dispatch

Explanation

Single dispatch resolves the method based on the receiver's type. Double dispatch considers both the receiver and the argument's types.

Report an error in this question

Object-Oriented Programming (OOP)Hard

Q30. What is metaclass programming?

  1. A.Creating graphical user interfaces programmatically
  2. B.Writing classes whose instances are themselves classes✓ Correct
  3. C.A commonly used structural design pattern for code
  4. D.Programming about programs in general terms

Explanation

A metaclass is a class whose instances are classes. Metaclass programming allows customizing class creation, adding behaviors, or enforcing constraints.

Report an error in this question

Ready to test yourself on Object-Oriented Programming (OOP)?

Take a timed quiz drawn from 210+ questions on this topic. No signup required — your progress saves in your browser.

Start Object-Oriented Programming (OOP) Quiz