Fundamental Programming MCQs

100 MCQs  (Page 9 of 10)

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
Why can't the this pointer be used inside a static member function?
A static member function is not called on an object, so there is no this
this is private
It can be used without restriction
this is const there