Object Oriented Programming MCQs with Answers
Practice important Object Oriented Programming MCQs with answers and explanations.
Chapter: 21
Q341:
What is the output of the following code? String s(“434"); cout << s.AsInt();
A. Junk value
B. 434
D. -1
Correct Answer:
B
Chapter: 21
Q342:
The type conversion from String to int is implemented using which function?
A. operator int()
B. operator char*()
C. AsInt()
D. GetStringPtr()
Correct Answer:
A
Chapter: 21
Q343:
In the modified String class, what does the GetStringPtr() function return?
A. The size of the string
B. A pointer to the string
C. The integer value
D. NULL
Correct Answer:
B
Chapter: 22
Q344:
What is the relationship represented by inheritance in C++?
A. HAS A
B. IS A
C. USES A
D. CONTAINS A
Correct Answer:
B
Chapter: 22
Q345:
In C++, which of the following is NOT a type of inheritance?
A. Public
B. Private
C. Protected
D. Virtual
Correct Answer:
D
Chapter: 22
Q346:
What is the class that inherits from another class called?
A. Base Class
B. Parent Class
C. Derived Class
D. None of the above
Correct Answer:
C
Chapter: 22
Q347:
What is the class whose behavior is being inherited called?
A. Base Class
B. Derived Class
C. Child Class
D. Sibling Class
Correct Answer:
A
Chapter: 22
Q348:
In C++, public members of a base class become what in the derived class?
A. Private members
B. Protected members
C. Public members
D. No access
Correct Answer:
C
Chapter: 22
Q349:
In C++, the default constructor of a base class must exist if:
A. The derived class object is created
B. The derived class has a destructor
C. The derived class has a constructor
D. The derived class does not exist
Correct Answer:
A
Chapter: 22
Q350:
Which constructor is executed first when an object of a derived class is created?
A. Derived class constructor
B. Base class constructor
C. Any constructor
D. None of the above
Correct Answer:
B
Chapter: 22
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
Correct Answer:
B
Chapter: 22
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
Correct Answer:
B
Chapter: 22
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
Correct Answer:
A
Chapter: 22
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
Correct Answer:
A
Chapter: 22
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()
Correct Answer:
D
Chapter: 22
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
Correct Answer:
B
Chapter: 22
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
Correct Answer:
A
Chapter: 22
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
Correct Answer:
B
Chapter: 22
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
Correct Answer:
C
Chapter: 22
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
Correct Answer:
A