In C++, when a derived class overrides a virtual function from a base class, which access specifier must be used to ensure proper polymorphic behavior?
AThe derived class function must use the same access specifier as the base class
BThe derived class function can use any access specifier regardless of base class
CThe derived class function must always be public
DThe derived class function must be private for security
Correct Answer:
B. The derived class function can use any access specifier regardless of base class
EXPLANATION
In C++, a derived class can override a virtual function with a different access specifier than the base class. The access specifier controls who can call the function, but it doesn't affect the polymorphic behavior. However, it's a best practice to maintain the same access level.
Which of the following best describes the concept of method overloading?
AMultiple functions with the same name and same parameters
BMultiple functions with the same name but different parameters or return types
CA derived class defining a function with the same name as the base class
DUsing virtual functions to achieve runtime polymorphism
Correct Answer:
B. Multiple functions with the same name but different parameters or return types
EXPLANATION
Method overloading allows multiple functions with the same name but different parameter lists (number, type, or order). Return type alone is insufficient for overloading.
What is the primary use of the 'const' keyword when applied to member functions?
ATo prevent the function from modifying object data members
BTo prevent the function from being called
CTo make the function static
DTo optimize function execution speed
Correct Answer:
A. To prevent the function from modifying object data members
EXPLANATION
A const member function cannot modify any non-static data members of the object. It guarantees that calling the function will not change the object's state.
Which of the following statements about constructors is correct?
AConstructors can have a return type
BConstructors are automatically called when an object is created
CA class can have only one constructor
DConstructors are inherited automatically in all derived classes
Correct Answer:
B. Constructors are automatically called when an object is created
EXPLANATION
Constructors have no return type, a class can have multiple constructors (constructor overloading), and constructors are not automatically inherited in C++ (until C++11 explicit inheritance). They are automatically invoked when objects are created.
What is the output of the following code?
class A { public: virtual void func() { cout
AA
BB
CC
DCompilation Error
Correct Answer:
C. C
EXPLANATION
With virtual functions, the actual object type (C) determines which function is called, not the pointer type. C::func() is invoked through multilevel inheritance.
Consider a scenario where a derived class needs to access a base class member that should not be accessible to external code. Which access specifier should be used in the base class?
Apublic
Bprotected
Cprivate
Dinternal
Correct Answer:
B. protected
EXPLANATION
The 'protected' access specifier allows access within the class and derived classes, but not to external code. This is ideal for members that derived classes need to use but external code should not access.
In which scenario would you use an abstract base class instead of a concrete base class?
AWhen you want to create many instances of the base class
BWhen you want to define an interface that derived classes must implement
CWhen you want faster execution
DWhen you want to save memory
Correct Answer:
B. When you want to define an interface that derived classes must implement
EXPLANATION
Abstract base classes are used to define interfaces and contracts that derived classes must follow. They cannot be instantiated but force derived classes to implement certain behaviors through pure virtual functions.
Which of the following is an example of operator overloading as a member function?
Afriend ostream& operator
BClass operator+(const Class&);
Coperator Class() { return *this; }
Doperator==() friend function
Correct Answer:
B. Class operator+(const Class&);
EXPLANATION
Option B shows operator overloading as a member function. The operator is defined as a member function of the class, which takes the second operand as a parameter.
What is the primary advantage of using virtual functions in a base class?
ATo improve compilation speed
BTo enable runtime polymorphism and allow derived classes to override behavior
CTo reduce memory usage
DTo make functions faster
Correct Answer:
B. To enable runtime polymorphism and allow derived classes to override behavior
EXPLANATION
Virtual functions enable runtime polymorphism, allowing the correct derived class method to be called through a base class pointer or reference, facilitating flexible and extensible code design.
iGET offers 49+ free C++ Programming MCQ questions covering all important topics. Each question is prepared by subject experts and comes with detailed explanations to help you understand concepts deeply, not just memorize answers.
Why prepare with iGET?
100% free access, timed mock tests, instant results with detailed analysis, topic-wise progress tracking, and bookmark feature for revision. Trusted by thousands of aspirants preparing for UPSC, SSC, Bank, Railway, NEET, JEE and other competitive exams across India.
How to use this page effectively
Start by selecting a difficulty level (Easy / Medium / Hard) or pick a specific topic from the topics strip. Attempt questions, check your answer instantly, read the explanation carefully, and bookmark tricky ones for later revision. For full exam-style practice, take a Mock Test from the right sidebar.
IGET AI
Online · Exam prep assistant
Hi! 👋 I'm your iget AI assistant.
Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯