Practice C++ Programming MCQ questions with detailed answers and step-by-step explanations. 100+ free questions available with instant solutions — perfect for competitive exam preparation.
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.
An abstract class in C++ is one that contains at least one pure virtual function. Which statement about abstract classes is TRUE?
AAbstract classes can be instantiated if all pure virtual functions are defined
BAbstract classes cannot be instantiated directly but can be used as base classes
CAbstract classes must contain only pure virtual functions
DAbstract classes cannot have constructors
Correct Answer:
B. Abstract classes cannot be instantiated directly but can be used as base classes
EXPLANATION
An abstract class with at least one pure virtual function cannot be instantiated directly. However, it serves as a blueprint for derived classes and can have constructors, destructors, and other functions.
What will be the output?
class Test { public: static int count; };
int Test::count = 0;
int main() { Test t1, t2; Test::count = 5; cout
A0 0
B5 5
C5 0
DCompilation Error
Correct Answer:
B. 5 5
EXPLANATION
Static members are shared by all instances of a class. When Test::count is set to 5, this value is shared across all objects t1 and t2, so both print 5.
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.
What problem does the Diamond Problem primarily address in multiple inheritance?
AA derived class inherits from two classes that share a common base class, causing ambiguity
BA base class cannot be inherited by more than two classes
CVirtual functions cannot be used in multiple inheritance
DMemory allocation becomes inefficient
Correct Answer:
A. A derived class inherits from two classes that share a common base class, causing ambiguity
EXPLANATION
The Diamond Problem occurs when a derived class inherits from two classes that both inherit from a common base class, creating multiple inheritance paths and ambiguity about which base class members to use. Virtual inheritance solves this.
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.
iGET offers 100+ 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! 🎯
iGET uses cookies for essential site functionality, analytics, and ads personalization (via Google AdSense). By clicking "Accept", you consent to our use of cookies.
Privacy Policy ·
Disclaimer