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.
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.
What is the key difference between shallow copy and deep copy in the context of copy constructors?
AShallow copy copies all members; deep copy copies only some members
BShallow copy creates bitwise copies; deep copy allocates new memory for dynamically allocated members
CDeep copy is faster but uses more memory
DShallow copy is used for virtual functions; deep copy is used for regular functions
Correct Answer:
B. Shallow copy creates bitwise copies; deep copy allocates new memory for dynamically allocated members
EXPLANATION
Shallow copy performs a bitwise copy of members, which can be problematic for pointers (both objects point to same memory). Deep copy allocates new memory for dynamic members, ensuring independent objects.
Consider the following code: class A { public: virtual ~A() {} }; class B : public A {}; int main() { A *ptr = new B(); delete ptr; }. What does the virtual destructor ensure?
AThe constructor is also virtual
BThe correct destructor sequence is called for derived class objects
CMemory is freed immediately after deletion
DThe pointer cannot be null
Correct Answer:
B. The correct destructor sequence is called for derived class objects
EXPLANATION
A virtual destructor ensures that when a derived class object is deleted through a base class pointer, the derived class destructor is called first, followed by the base class destructor, properly cleaning up all resources.
What is the relationship between references and pointers in C++ OOP context?
AReferences are safer than pointers but less flexible
BPointers provide more functionality than references
CReferences cannot be used for polymorphism, only pointers can
DBoth can be used equally for polymorphism, but references provide better safety
Correct Answer:
D. Both can be used equally for polymorphism, but references provide better safety
EXPLANATION
Both references and pointers can be used for polymorphism in C++. References are generally safer (no null references, cannot be reassigned) while pointers are more flexible (can be null, reassigned).
Consider a scenario where class C inherits from both class A and class B, and both A and B have a method foo(). Which statement correctly resolves the ambiguity?
AC::foo() will automatically call both A::foo() and B::foo()
BC must explicitly override foo() or use scope resolution operator to specify which foo() to call
CThe compiler will automatically choose one based on declaration order
DC cannot inherit from both A and B in this case
Correct Answer:
B. C must explicitly override foo() or use scope resolution operator to specify which foo() to call
EXPLANATION
In multiple inheritance, if both base classes have the same method, the derived class must either override it or use the scope resolution operator (A::foo() or B::foo()) to specify which one to call.
In a multiple inheritance scenario with diamond problem, how does C++ resolve ambiguity?
AAutomatically chooses one base class
BRequires virtual inheritance
CThrows a compilation error
DUses runtime resolution
Correct Answer:
B. Requires virtual inheritance
EXPLANATION
The diamond problem occurs when a derived class inherits from two classes that have a common base. Virtual inheritance ensures only one copy of the base class is created.
iGET offers 23+ 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! 🎯