Object Oriented Programming MCQs with Answers
Practice important Object Oriented Programming MCQs with answers and explanations.
Multiple Choice Questions
Q351: In C++, if a base class has a non-default constructor, what should be done in the derived class?
- A: Use the default constructor
- B: Call the base class non-default constructor
- C: Avoid using constructors
- D: Ignore the base class constructor
View Answer
B
Q352: What does the following code do? "Child()
- A: Calls the derived class constructor first
- B: Calls the base class constructor first
- C: Initializes the base class members
- D: Does nothing
View Answer
B
Q353: What is the correct order of destructor calls in inheritance in C++?
- A: Derived class first, then base class
- B: Base class first, then derived class
- C: Random order
- D: No destructor calls are needed
View Answer
A
Q354: What happens if a base class has only a non-default constructor, and the derived class does not call it?
- A: Compiler generates an error
- B: Compiler generates a default constructor
- C: No error occurs
- D: The derived class will not be compiled
View Answer
A
Q355: Which syntax is used to explicitly call a base class constructor in C++?
- A: BaseClass()
- B: DerivedClass::BaseClass()
- C: DerivedClass() : BaseClass()
- D: ChildClass() : ParentClass()
View Answer
D
Q356: In UML notation, how is inheritance represented?
- A: By a dashed arrow from base to derived class
- B: By a solid arrow from derived to base class
- C: By a dotted line
- D: By a rectangle enclosing both classes
View Answer
B
Q357: In the following code: "class Student: public Person{}", what does "public" signify?
- A: Public inheritance
- B: Public members only
- C: All members are public
- D: No inheritance
View Answer
A
Q358: Which member of the base class is initialized first in the derived class?
- A: The last declared member
- B: The first declared member
- C: The derived class member
- D: The last member of the derived class
View Answer
B
Q359: What happens when the derived class does not initialize the base class in the initializer list?
- A: Compiler generates a warning
- B: Compiler generates a runtime error
- C: Compiler generates a compile-time error
- D: Nothing
View Answer
C
Q360: How can a derived class in C++ initialize its base class members?
- A: Using overloaded constructors in base class
- B: Using default constructors
- C: Using public members of base class directly
- D: By assignment in the derived class
View Answer
A