Skip to main content

Object Oriented Programming MCQs with Answers

Practice important Object Oriented Programming MCQs with answers and explanations.

Chapter: 22
Q361:
In C++, what will happen if a derived class does not define a destructor?
A. Base class destructor will be called first
B. No destructor will be called
C. Derived class destructor will be called
D. Only base class destructor will be called
Correct Answer: A
Chapter: 23
Q362:
What does a default constructor allow?
A. Create class object with no arguments
B. Create class object with arguments
C. Prevent class instantiation
D. Access private members of the class
Correct Answer: A
Chapter: 23
Q363:
What happens if a base class has only a non-default constructor?
A. Derived class inherits it
B. Compiler generates a default constructor
C. Compiler generates an error
D. Constructor is ignored
Correct Answer: C
Chapter: 23
Q364:
How can a base class's non-default constructor be called in a derived class?
A. Through base class object
B. In derived class constructor
C. Through a public method
D. By using friend function
Correct Answer: B
Chapter: 23
Q365:
What is the purpose of the IsLeapYear function in the Date class?
A. To set the day
B. To check if a year is a leap year
C. To add a day
D. To reset the date
Correct Answer: B
Chapter: 23
Q366:
Why are helper functions often made private?
A. To prevent external access
B. To ensure faster execution
C. To allow inheritance
D. To improve readability
Correct Answer: A
Chapter: 23
Q367:
Which access specifier should be used to allow derived classes to access a function but not external classes?
A. Public
B. Private
C. Protected
D. Friend
Correct Answer: C
Chapter: 23
Q368:
What is the primary disadvantage of using protected members?
A. Increases accessibility
B. Breaks encapsulation
C. Enhances performance
D. Reduces code readability
Correct Answer: B
Chapter: 23
Q369:
What does public inheritance model?
A. "HAS A" relationship
B. "DOES A" relationship
C. "IS A" relationship
D. "WILL BE A" relationship
Correct Answer: C
Chapter: 23
Q370:
When can a derived class object be used?
A. When base class object is required
B. When base class object is not required
C. Only in special cases
D. Never
Correct Answer: A
Chapter: 23
Q371:
What is static typing?
A. A dynamic type system
B. The type used to declare a reference or pointer
C. Runtime type identification
D. A debugging method
Correct Answer: B
Chapter: 23
Q372:
What happens if you try to access derived class methods using a base class reference?
A. The method is called
B. The program crashes
C. The compiler generates an error
D. The method is ignored
Correct Answer: C
Chapter: 23
Q373:
How can a function parameter of a base class type be initialized?
A. Only with a base class object
B. With a derived class object
C. With any object
D. It cannot be initialized
Correct Answer: B
Chapter: 23
Q374:
What will the following code output? cout << pPtr->GetRollNo(); where pPtr is of type Person*.
A. The roll number
B. A compile-time error
C. Undefined behavior
D. Nothing
Correct Answer: B
Chapter: 24
Q375:
What is the main purpose of protected members in a class?
A. To allow access only within the class
B. To allow access from derived classes
C. To allow access from anywhere
D. To prevent any access
Correct Answer: B
Chapter: 24
Q376:
In C++, public inheritance represents which type of relationship between classes?
A. HAS-A
B. IS-A
C. USES-A
D. PART-OF
Correct Answer: B
Chapter: 24
Q377:
Which access specifier allows derived classes to access base class members but denies access to other classes?
A. Public
B. Private
C. Protected
D. Friend
Correct Answer: C
Chapter: 24
Q378:
What is the issue with using shallow copy in classes that utilize dynamic memory allocation?
A. It copies all data correctly
B. It leads to duplicate memory allocation
C. Both objects share the same memory location
D. It is faster than deep copy
Correct Answer: C
Chapter: 24
Q379:
How do you explicitly call a base class copy constructor in a derived class?
A. By using the 'super' keyword
B. By calling it in the derived class constructor's body
C. By using base class name in the initialization list
D. It is called automatically
Correct Answer: C
Chapter: 24
Q380:
What happens if you do not explicitly call the base class copy constructor in a derived class copy constructor?
A. Base class copy constructor is called automatically
B. Base class default constructor is called
C. Base class constructor is not called
D. Program will not compile
Correct Answer: B

Test Your Knowledge

Take a timed quiz on Object Oriented Programming

🚀 Start Quiz Now