Section 1: Core Concepts & Basics of OOP
Q1. Which of the following is NOT one of the core pillars of Object-Oriented Programming?
(A) Encapsulation
(B) Inheritance
(C) Compilation
(D) Polymorphism
Correct Answer: (C) Compilation
Explanation: The four core pillars of OOP are Encapsulation, Inheritance, Polymorphism, and Abstraction. Compilation is a language translation process, not an OOP principle.
Q2. What is a class in Object-Oriented Programming?
(A) A real-world physical entity
(B) A blueprint or user-defined template from which objects are created
(C) A built-in data type like int or float
(D) A function that executes automatically at startup
Correct Answer: (B) A blueprint or user-defined template from which objects are created
Explanation: A class defines the attributes (variables) and behaviors (methods) that objects created from it will possess.
Q3. An object is an instance of a:
(A) Method
(B) Variable
(C) Class
(D) Package
Correct Answer: (C) Class
Explanation: When a class is instantiated, it allocates memory and creates an individual object with its own state and identity.
Q4. Which access specifier makes class members accessible only within the class itself?
(A) Public
(B) Protected
(C) Private
(D) Default
Correct Answer: (C) Private
Explanation: Private members cannot be accessed or viewed from outside the class, ensuring strict data hiding and encapsulation.
Q5. What is the main purpose of a Constructor in a class?
(A) To destroy an object when it goes out of scope
(B) To initialize the values of object attributes when the object is created
(C) To copy data from one database to another
(D) To inherit properties from a parent class
Correct Answer: (B) To initialize the values of object attributes when the object is created
Explanation: A constructor is a special member function that has the same name as the class and executes automatically upon object instantiation.
Q6. What is the name of the special member function that is automatically invoked when an object is destroyed?
(A) Constructor
(B) Destructor
(C) Terminator
(D) Deallocator
Correct Answer: (B) Destructor
Explanation: A destructor cleans up resources and memory allocated to the object. It is prefixed with a tilde symbol (~) in C++.
Q7. Which concept allows a class to acquire the properties and methods of another class?
(A) Polymorphism
(B) Encapsulation
(C) Inheritance
(D) Abstraction
Correct Answer: (C) Inheritance
Explanation: Inheritance promotes code reusability by allowing a derived (child) class to inherit features from a base (parent) class.
Q8. What does “Polymorphism” literally mean in object-oriented programming?
(A) Multiple inheritance paths
(B) Many forms
(C) Hiding data fields
(D) Dynamic memory allocation
Correct Answer: (B) Many forms
Explanation: Polymorphism allows a single function name, operator, or pointer to behave in different ways based on the context or object type.
Q9. Wrapping data and member functions together into a single unit is called:
(A) Inheritance
(B) Encapsulation
(C) Polymorphism
(D) Abstraction
Correct Answer: (B) Encapsulation
Explanation: Encapsulation binds data and the methods manipulating that data together while hiding internal implementation details from the outside world.
Q10. What is Data Abstraction?
(A) Showing only essential features and hiding background implementation details
(B) Copying an object’s state into a file
(C) Creating multiple copies of a single object
(D) Converting source code into machine code
Correct Answer: (A) Showing only essential features and hiding background implementation details
Explanation: Abstraction focuses on what an object does rather than how it achieves it (e.g., using abstract classes and interfaces).
Section 2: Advanced OOP Concepts & Functions
Q11. Which type of inheritance occurs when a class is derived from more than one base class?
(A) Single Inheritance
(B) Multilevel Inheritance
(C) Multiple Inheritance
(D) Hierarchical Inheritance
Correct Answer: (C) Multiple Inheritance
Explanation: In multiple inheritance, a child class inherits characteristics from two or more parent classes (e.g., class C inherits from class A and class B).
Q12. What famous issue arises in multiple inheritance when a child class inherits from two parent classes that share a common base class?
(A) Memory leak
(B) Diamond Problem
(C) Stack overflow
(D) Pointer dangling
Correct Answer: (B) Diamond Problem
Explanation: The diamond problem creates ambiguity regarding which parent’s version of a method or variable the child should inherit. It is solved using virtual inheritance.
Q13. Function overloading is an example of which type of polymorphism?
(A) Run-time (Dynamic) polymorphism
(B) Compile-time (Static) polymorphism
(C) Ad-hoc abstraction
(D) Virtual polymorphism
Correct Answer: (B) Compile-time (Static) polymorphism
Explanation: Function overloading and operator overloading are resolved during compile-time based on function signatures.
Q14. Function overriding (using virtual functions) is an example of:
(A) Compile-time polymorphism
(B) Run-time polymorphism
(C) Static binding
(D) Operator masking
Correct Answer: (B) Run-time polymorphism
Explanation: Run-time polymorphism is achieved using virtual functions where the method call is resolved dynamically during execution based on the object type.
Q15. What is a Pure Virtual Function?
(A) A function that cannot be overridden in derived classes
(B) A virtual function with no body (assigned to 0) that must be implemented by derived classes
(C) A function executing directly inside hardware registers
(D) A constructor marked as private
Correct Answer: (B) A virtual function with no body (assigned to 0) that must be implemented by derived classes
Explanation: A class containing at least one pure virtual function becomes an Abstract Class, meaning it cannot be instantiated directly.
Q16. What is a Friend Function in C++?
(A) A function that can access private and protected members of a class without being a member of that class
(B) A function inherited from a parent class
(C) A constructor used to create friendly objects
(D) A built-in standard library function
Correct Answer: (A) A function that can access private and protected members of a class without being a member of that class
Explanation: Declared with the friend keyword inside a class, external functions or other classes gain access to private data.
Q17. What does the this pointer represent inside a non-static member function?
(A) The address of the base class
(B) The address of the currently invoking object
(C) A pointer to the global namespace
(D) The size of the class in bytes
Correct Answer: (B) The address of the currently invoking object
Explanation: this is a hidden pointer passed to all non-static member functions, pointing to the object for which the function was called.
Q18. What is a Copy Constructor used for?
(A) To copy files from hard disk to RAM
(B) To initialize a new object using an existing object of the same class
(C) To duplicate a class definition at runtime
(D) To backup source code files
Correct Answer: (B) To initialize a new object using an existing object of the same class
Explanation: Copy constructors take a reference to an object of the same class (e.g., ClassName(const ClassName &obj)) to perform shallow or deep copies.
Q19. Which relationship represents a “Has-A” association between classes?
(A) Inheritance
(B) Composition / Aggregation
(C) Polymorphism
(D) Overloading
Correct Answer: (B) Composition / Aggregation
Explanation: “Is-A” represents inheritance, while “Has-A” represents composition or aggregation (where one class contains an instance of another class).
Q20. What is a static member variable in a class?
(A) A variable whose value cannot be changed
(B) A variable shared among all objects of the class rather than having a unique copy per object
(C) A variable stored temporarily on the stack
(D) A private variable accessible only by friend functions
Correct Answer: (B) A variable shared among all objects of the class rather than having a unique copy per object
Explanation: Static members belong to the class as a whole rather than any specific instance, and they retain their values across object lifetimes.
Q21. Which keyword is used to prevent a class from being inherited in C++?
(A) static
(B) final
(C) sealed
(D) private
Correct Answer: (B) final
Explanation: In modern C++, appending the final specifier to a class definition prevents any other class from inheriting from it.
Q22. What is the output of dynamic binding?
(A) Function execution speed is increased at compile time
(B) The correct function implementation is selected at runtime based on object type
(C) Memory allocation is fixed statically
(D) Syntax errors are caught immediately
Correct Answer: (B) The correct function implementation is selected at runtime based on object type
Explanation: Dynamic binding (late binding) relies on virtual tables (vtables) to determine which overridden function to call during execution.
Q23. Which access modifier allows members to be accessed by derived classes but keeps them hidden from outside classes?
(A) Public
(B) Private
(C) Protected
(D) Global
Correct Answer: (C) Protected
Explanation: Protected members act like private members to the outside world, but remain fully accessible to child (derived) classes.
Q24. Can a constructor be virtual?
(A) Yes, always
(B) No, constructors cannot be virtual
(C) Yes, only in abstract classes
(D) Only if declared inline
Correct Answer: (B) No, constructors cannot be virtual
Explanation: A virtual mechanism relies on an existing object vtable pointer, but a constructor’s job is to create that object and set up the vtable, so it cannot be virtual. (Note: Destructors can and often should be virtual).
Q25. What is an Abstract Data Type (ADT)?
(A) A data type defined by its behavior from the user’s point of view, hiding implementation details
(B) A primitive data type like integer or character
(C) A hardware register description
(D) A compiler optimization flag
Correct Answer: (A) A data type defined by its behavior from the user’s point of view, hiding implementation details
Explanation: ADTs specify what operations can be performed and what values can be stored, without disclosing how the data structures are implemented internally.
Section 3: Advanced OOP Principles & Design Patterns
Q26. What is the primary benefit of using Interfaces or Pure Abstract Classes in OOP?
(A) To increase the size of compiled binaries
(B) To enforce a strict contract or standard structure that implementing classes must follow
(C) To bypass compiler error checks
(D) To allow direct access to private hardware memory
Correct Answer: (B) To enforce a strict contract or standard structure that implementing classes must follow
Explanation: Interfaces define what methods a class must implement without dictating how they are implemented, supporting decoupled architecture and multiple inheritance behaviors.
Q27. What is Object Slicing in C++?
(A) Deleting an object from heap memory safely
(B) Assigning a derived class object to a base class object, causing the derived part’s data and methods to be “sliced off”
(C) Splitting a class file into multiple header files
(D) Dividing an array of objects into chunks
Correct Answer: (B) Assigning a derived class object to a base class object, causing the derived part’s data and methods to be “sliced off”
Explanation: Object slicing happens when passing derived objects by value rather than by reference or pointer, losing the specialized attributes and polymorphic behavior of the derived class.
Q28. Which design pattern ensures that a class has only one instance and provides a global point of access to it?
(A) Factory Pattern
(B) Singleton Pattern
(C) Observer Pattern
(D) Adapter Pattern
Correct Answer: (B) Singleton Pattern
Explanation: The Singleton pattern restricts instantiation of a class to a single object, commonly managed via a private constructor and a public static access method.
Q29. What is Association in Object-Oriented Modeling?
(A) A strict parent-child ownership where child objects are destroyed with the parent
(B) A relationship connecting two separate classes that establishes a semantic connection
(C) A method overriding mechanism
(D) A syntax error in object instantiation
Correct Answer: (B) A relationship connecting two separate classes that establishes a semantic connection
Explanation: Association represents general “uses-a” or “knows-a” relationships between independent classes without enforcing strict lifetime ownership.
Q30. What distinguishes Composition from Aggregation?
(A) Composition represents a whole-part relationship where the part cannot exist independently of the whole (strict ownership), whereas Aggregation is a weaker “has-a” relationship where parts can exist independently
(B) Composition uses inheritance while Aggregation uses templates
(C) Composition applies only to static variables
(D) There is no structural difference
Correct Answer: (A) Composition represents a whole-part relationship where the part cannot exist independently of the whole (strict ownership), whereas Aggregation is a weaker “has-a” relationship where parts can exist independently
Explanation: For example, a House and its Rooms form a composition (if the house is destroyed, rooms are destroyed), while a Department and its Professors form an aggregation (if the department closes, professors still exist).
Q31. What is Late Binding (Dynamic Binding)?
(A) Resolving function calls at compile time based on exact variable declarations
(B) Resolving function calls at runtime based on the actual type of the object pointed or referenced to
(C) Allocating memory blocks dynamically on the heap
(D) Linking library files during executable startup
Correct Answer: (B) Resolving function calls at runtime based on the actual type of the object pointed or referenced to
Explanation: Late binding is core to runtime polymorphism, enabling base class pointers to invoke overridden methods in derived classes.
Q32. What is Method Overriding?
(A) Defining multiple methods with the same name but different parameter lists in the same class
(B) Providing a specific implementation in a derived class for a method that is already defined in its base class
(C) Changing private variables using friend functions
(D) Hiding a base class method by changing its return type
Correct Answer: (B) Providing a specific implementation in a derived class for a method that is already defined in its base class
Explanation: Overriding requires matching signatures, return types, and virtual declarations in the inheritance hierarchy.
Q33. What is Method Overloading?
(A) Having multiple methods in the same scope with the same name but different parameters (number, type, or order)
(B) Replacing a parent class function in a child class
(C) Calling a function recursively until stack overflow occurs
(D) Running multiple threads simultaneously inside an object
Correct Answer: (A) Having multiple methods in the same scope with the same name but different parameters (number, type, or order)
Explanation: Method overloading is a compile-time (static) polymorphism feature that enhances code readability.
Q34. Which of the following is true regarding Constructors?
(A) Constructors must have a return type like int or void
(B) Constructors cannot be overloaded
(C) Constructors have the same name as the class and no return type
(D) Constructors are inherited by derived classes automatically
Correct Answer: (C) Constructors have the same name as the class and no return type
Explanation: Constructors do not return values (not even void) and can be overloaded to provide multiple ways of initializing objects.
Q35. What is a Virtual Destructor used for?
(A) To speed up garbage collection
(B) To ensure that the destructor of the derived class is called when an object is deleted through a base class pointer, preventing memory leaks
(C) To make the class abstract
(D) To allow multiple inheritance of destructors
Correct Answer: (B) To ensure that the destructor of the derived class is called when an object is deleted through a base class pointer, preventing memory leaks
Explanation: If a base class pointer deletes a derived object without a virtual destructor, only the base destructor runs, leaking resources allocated in the derived class.
Section 4: Advanced Memory Management & Advanced OOP Concepts
Q36. What is a Memory Leak in C++ object-oriented applications?
(A) Unauthorized reading of private variables across objects
(B) Allocated heap memory that is never deallocated because pointers to it were lost, wasting system resources
(C) Overflowing stack space during recursive constructor calls
(D) Slow execution speed due to excessive virtual table lookups
Correct Answer: (B) Allocated heap memory that is never deallocated because pointers to it were lost, wasting system resources
(Note: Modern C++ mitigates leaks using smart pointers like std::unique_ptr and std::shared_ptr).
Q37. What is a Smart Pointer?
(A) A pointer variable that stores computer IP addresses
(B) An abstract data type that simulates a pointer while providing automatic memory management features to prevent memory leaks
(C) A pointer that points directly to CPU hardware registers
(D) A function argument passed by reference
Correct Answer: (B) An abstract data type that simulates a pointer while providing automatic memory management features to prevent memory leaks
Explanation: Smart pointers (like unique_ptr and shared_ptr) automatically free heap memory when they go out of scope.
Q38. What is Multiple Inheritance ambiguity resolved by?
(A) Using garbage collection flags
(B) Explicit scope resolution operator (::) or virtual base classes
(C) Changing all methods to private access
(D) Using dynamic casting exclusively
Correct Answer: (B) Explicit scope resolution operator (::) or virtual base classes
Explanation: When two base classes have a function with the same name, the derived class must specify which one to call using BaseClass::functionName().
Q39. What is the purpose of the explicit keyword in C++ constructors?
(A) To make the constructor public and globally visible
(B) To prevent implicit type conversions or coercions by single-argument constructors
(C) To speed up execution time of object instantiation
(D) To force the constructor to run in kernel mode
Correct Answer: (B) To prevent implicit type conversions or coercions by single-argument constructors
Explanation: Using explicit avoids unintended bugs caused by the compiler implicitly converting values into class objects.
Q40. What is Cohesion in software engineering and OOP?
(A) The measure of how strongly-related and focused the responsibilities of a single module or class are
(B) The degree of dependency between different software modules
(C) The speed at which objects communicate via network sockets
(D) The process of combining multiple classes into a single file
Correct Answer: (A) The measure of how strongly-related and focused the responsibilities of a single module or class are
Explanation: Good object-oriented design aims for high cohesion (each class does one specific job well) and low coupling (classes are independent).
Q41. What is Coupling in object-oriented design?
(A) The internal logic complexity of a loop
(B) The degree of direct interdependence between software modules or classes
(C) The process of linking class libraries at runtime
(D) The size of an object in bytes
Correct Answer: (B) The degree of direct interdependence between software modules or classes
Explanation: Low coupling is desirable because changes in one class are less likely to ripple and break other parts of the codebase.
Q42. Which of the following is true regarding static member functions?
(A) They can access non-static member variables directly
(B) They have access to the this pointer
(C) They can only access other static members and can be called without creating an object instance
(D) They must be declared as virtual functions
Correct Answer: (C) They can only access other static members and can be called without creating an object instance
Explanation: Because static member functions belong to the class rather than any object instance, they do not possess a this pointer.
Q43. What is Operator Overloading?
(A) Creating new operators like +++ or ---
(B) Giving special meaning to existing operators (like +, -, ==) when applied to user-defined classes
(C) Overloading system CPU cores with heavy arithmetic tasks
(D) Changing the precedence of arithmetic operations
Correct Answer: (B) Giving special meaning to existing operators (like +, -, ==) when applied to user-defined classes
Explanation: Operator overloading allows custom objects to be manipulated with natural syntax (e.g., adding two Complex number objects using c1 + c2).
Q44. What is a Local Class in C++?
(A) A class defined inside a function block
(B) A class defined inside the global namespace
(C) A class that can only be accessed within the same file
(D) A class containing only static variables
Correct Answer: (A) A class defined inside a function block
Explanation: Local classes have restricted scopes and can only use local variables, static variables, and global variables from their enclosing scope.
Q45. What is Covariant Return Type in method overriding?
(A) A derived class overriding method returning a pointer or reference to a derived class instead of the base class’s return type
(B) Returning multiple values from a single function
(C) Returning error codes on failure
(D) Overloading functions with different return types
Correct Answer: (A) A derived class overriding method returning a pointer or reference to a derived class instead of the base class’s return type
Explanation: C++ permits an overridden virtual function in a child class to return a pointer/reference to a child type rather than the parent type.
Q46. What is a Nested Class?
(A) A class declared inside another class
(B) A class that inherits from multiple base classes simultaneously
(C) A template class inside another template
(D) A class wrapped inside a namespace
Correct Answer: (A) A class declared inside another class
Explanation: Nested classes (inner classes) help encapsulate helper data structures that are only relevant to the enclosing (outer) class.
Q47. Which feature is used to implement generic programming in C++?
(A) Virtual Functions
(B) Templates (Function and Class Templates)
(C) Friend Classes
(D) Multiple Inheritance
Correct Answer: (B) Templates (Function and Class Templates)
Explanation: Templates allow writing code independent of data types, enabling generic data structures like std::vector and std::map.
Q48. What is Downcasting?
(A) Casting a base class pointer or reference to a derived class pointer or reference
(B) Casting a derived class pointer to a base class pointer
(C) Converting an integer to a floating-point number
(D) Reducing object memory allocation
Correct Answer: (A) Casting a base class pointer or reference to a derived class pointer or reference
Explanation: Downcasting (often performed safely via dynamic_cast with polymorphic classes) allows accessing specialized derived-class methods from a base reference.
Q49. What is the primary purpose of the const keyword on a member function (e.g., void display() const)?
(A) To make the function run faster
(B) To guarantee that the member function will not modify any non-mutable data members of the object
(C) To make the function private
(D) To prevent the function from being overridden
Correct Answer: (B) To guarantee that the member function will not modify any non-mutable data members of the object
Explanation: Const member functions can be safely called on constant objects without violating data immutability.
Q50. What is Subtype Polymorphism?
(A) Polymorphism achieved through function overloading
(B) Polymorphism achieved through inheritance and virtual functions, where a pointer/reference to a base type can transparently refer to any derived type
(C) Using operator overloading for arithmetic computations
(D) Compile-time template substitution
Correct Answer: (B) Polymorphism achieved through inheritance and virtual functions, where a pointer/reference to a base type can transparently refer to any derived type
Explanation: Subtype polymorphism allows unified treatment of objects belonging to different classes down an inheritance hierarchy.
Related Subject-wise MCQs:

12 Comments