Object-Oriented Concepts MCQs

13 MCQs  — Fundamental Programming MCQs  (Page 1 of 2)

Practice Object-Oriented Concepts MCQs with correct answers and explanations. These questions are from the Fundamental Programming MCQs section.

Which C++ members can be declared virtual?
Both can
Neither can
Destructors can be virtual; constructors cannot
Constructors can be virtual; destructors cannot
What makes a C++ class abstract?
It is declared with the abstract keyword
It has no constructor
It has at least one pure virtual function (= 0)
All of its members are private
What is the default member access in a C++ class and in a C++ struct?
class: private; struct: public
class: public; struct: private
Both private
Both public
Which statement correctly distinguishes overloading from overriding?
Both are resolved at run time
Overloading is resolved at compile time; overriding a virtual function is resolved at run time
Overriding requires different parameter lists
Overloading requires inheritance
The 'diamond problem' in C++ multiple inheritance is solved by which feature?
Virtual functions
Virtual inheritance
Abstract classes
Friend classes
In Python, a class defines self.__secret = 1. Which statement is true?
It causes a SyntaxError
It makes the attribute read-only
The name is mangled to _ClassName__secret but is still accessible from outside
It is truly private and inaccessible
Which statement about a C++ friend function is correct?
It is a member function with public access
It is inherited by derived classes
It is not a member of the class but can access the class's private members
It must be declared virtual
Why must a C++ copy constructor take its parameter by reference, as in X(const X&)?
Only for const-correctness
Because constructors cannot take value parameters
References are faster
Passing by value would require calling the copy constructor itself, causing infinite recursion
Which statement about a static data member of a C++ class is correct?
A single copy is shared by all objects of the class
Each object gets its own copy
It cannot be modified
It is stored on the stack