Virtual Functions MCQs: 11 Solved C++ Runtime Polymorphism Questions
Test C++ virtual dispatch with 11 solved exam MCQs, worked explanations and three code traces covering final overriders and safe base-class destruction.
KnowledgeGate Team
Exam prep & CS education

Base* p = new Derived; Which implementation runs when the call is p->show()? The answer depends on whether show is virtual, not merely on inheritance. DSSSB, UGC NET, BPSC, KVS, TPSC and IT placement questions test definitions, pure-virtual syntax, static-member restrictions, dispatch traces and destructor safety. Apply the virtual-dispatch rule to identify the correct option and justify it. Practise more in the Coding & DSA category.
1. Fix the virtual-dispatch rule before attempting the MCQs
Use struct Base { virtual int value() { return 10; } };, struct Derived : Base { int value() override { return 25; } };, then Base* p = new Derived;. The static type is Base*; the actual object is Derived.
Declaration | Static pointer type | Actual object | Virtual? | Selected function | Returned value |
|---|---|---|---|---|---|
|
|
| Yes |
|
|
Remove only |
|
| No |
|
|
The exam-safe rule is precise: an eligible virtual call through a base pointer or reference uses the actual object's final overrider. A non-virtual call is selected from compile-time information. Do not assume every member call through a base pointer is dynamic.
Two boundaries: virtual void show() = 0; is pure virtual and makes the class abstract. A static member cannot be virtual because no object invokes it. Study runnable vtable and vptr mechanics in Virtual Functions and VTable in C++, then use these eleven MCQs for answer selection, pure-virtual syntax, final overriders and destructor safety.
2. Virtual Functions MCQs 1-2: definition and runtime polymorphism
Question 1: DSSSB 2018, Computer Science
A ________ function is a member function in base class that you expect to redefine in derived classes.
A. Friend
B. Virtual
C. Private
D. Protected
Correct answer: B. Virtual. virtual enables runtime dispatch. The setup returns 25 from Derived::value(); friendship and access labels do not select overrides.
Question 2: TPSC 2026, Computer Science, System Analyst
The following feature of C++ is an example of run time polymorphism
A. OPERATOR OVERLOADING
B. POINTERS
C. TEMPLATES
D. VIRTUAL FUNCTION
Correct answer: D. VIRTUAL FUNCTION. Dispatch uses the actual object, so Base* p = new Derived; p->value() returns 25. Operator overloading and templates are normally compile-time; a pointer alone creates no polymorphism. Continue with the C++ Programming course.
3. Virtual Functions MCQs 3-4: pure virtual syntax and the runtime mechanism
Question 3: UGC NET 2024, Computer Science, August
Which of the following C++ statements correctly declares an abstract class?
A.
class A { virtual void show()=0; };B.
class A { void show()=0; };C.
class A { void show() { } };D.
class A { show()=0; };
Correct answer: A. class A { virtual void show()=0; };. Here = 0 makes the member pure and A abstract. B lacks virtual, C is concrete, and D lacks a return type and virtual. The concrete implementation class B : public A { public: void show() override { cout << 7; } }; prints 7.
Question 4: Kendriya Vidyalaya Sangathan 2018, Computer Science
Run-time polymorphism is achieved by _____.
A. friend function
B. virtual function
C. operator overloading
D. function overloading
Correct answer: B. virtual function. Virtual functions permit late selection, so the final overrider on the actual object runs. Function overloading picks a match from the argument types at compile time; friendship controls access, and operator overloading is normally compile-time.
4. Virtual Functions MCQs 5-6: abstract-class and static-member traps
Question 5: UGC NET 2023, Computer Science, December
Which of the following statements is TRUE ?
A. Virtual functions do not implement polymorphism
B. Virtual functions do not permit calling of derived class functions using a base class pointer
C. We can never build an object from a class containing a pure virtual function
D. Pure virtual functions can never have a body
Correct answer: C. We can never build an object from a class containing a pure virtual function. The class is abstract, but a concrete derived class is instantiable. A and B deny runtime dispatch. D is false because a pure virtual function may have an out-of-class definition.
Question 6: UGC NET 2017, Computer Science, November
Which of the following is not correct for a virtual function in C++?
A. Virtual functions can be declared in public, protected, or private sections of a class.
B. A virtual function can be static.
C. Virtual functions can be accessed using pointers or references.
D. A virtual function is declared in a base class so derived classes can override it.
Correct answer: B. A virtual function can be static. A static member has no this object for dispatch. Access control permits virtual members; pointers and references are standard dispatch routes. Review OOP for Teaching CS Exams: Classes and Inheritance.
5. Virtual Functions MCQs 7-8: statement logic and creating an abstract class
Question 7: DSSSB 2021, Computer Science
Which of the following is NOT correct about virtual functions in C++?
I. A virtual function must be a member of a class.
II. It can be accessed using an object pointer or reference.
A. Only I
B. Only II
C. Both I and II
D. Neither I nor II
Correct answer: D. Neither I nor II. I is true because a virtual function is a non-static member. II is true because a pointer or reference can invoke it. Derived d; Base& r = d; r.value() returns 25, so neither statement is incorrect.
Question 8: BPSC 2023, Computer Science, PGT Tier-1
Which of the following can be used to create an abstract class in the C++ programming language?
A. By using the pure virtual function in the class
B. By declaring a virtual function in the base class
C. By declaring the virtual keyword afterward the class declaration
D. More than one of the above
E. None of the above
Correct answer: A. By using the pure virtual function in the class. virtual int score() = 0; makes a class abstract; an ordinary virtual function does not. virtual after the class declaration is invalid, so D fails.
6. Virtual Functions MCQs 9-11: trace the final overrider and destructor boundary

The code-trace questions test virtual dispatch and destructor behavior. Write the output before reading each explanation.
Question 9: TCS 2024
#include <iostream>
using namespace std;
template <int N>
class A {
int arr[N];
public:
virtual void fun() { cout << "A::fun()"; }
};
class B : public A<2> {
public:
void fun() { cout << "B::fun()"; }
};
class C : public B { };
int main() {
A<2> *a = new C;
a->fun();
return 0;
}A.
A::fun()B.
0C.
errorD.
B::fun()
Correct answer: D. B::fun(). The pointer is A<2>*, but the object is C. Because C has no override, its final overrider is B::fun(). The template and arr[2] do not affect dispatch.
Question 10: TCS 2026
#include <iostream>
using namespace std;
class A
{
public:
virtual void fun() {cout << "A" << endl ;}
};
class B: public A
{
public:
virtual void fun() {cout << "B" << endl;}
};
class C: public B
{
public:
virtual void fun() {cout << "C" << endl;}
};
int main()
{
A *a = new C;
A *b = new B;
a->fun();
b->fun();
return 0;
}A.
C
BB.
A
B
CC.
B
CD.
A
BCorrect answer: A. C followed by B on the next line. Actual object C makes a print C; actual object B makes b print B.
Question 11: Hexaware/CoCubes 2025
Consider the following given program and choose the most appropriate output from the given options:
using namespace std;
class Base {
public:
Base()
{ cout<<"Constructing Base \n"; }
~Base()
{ cout<<"Destructing Base \n"; }
};
class Derived: public Base {
public:
Derived()
{ cout<<"Constructing Derived \n"; }
~Derived()
{ cout<<"Destructing Derived \n"; }
};
int main(void)
{
Derived *d = new Derived();
Base *b = d;
delete b;
return 0;
}A. Constructing Base, Constructing Derived, Destructing Base, Destructing Derived
B. Constructing Base, Constructing Derived, Destructing Base
C. Constructing Base, Constructing Derived, Destructing Derived, Destructing Base
D. None of the above
Correct answer: D. None of the above. Construction prints Constructing Base, then Constructing Derived. After that, delete b; has undefined behaviour because Base lacks a virtual destructor, so the standard guarantees no exact destruction sequence and none of A-C is correct. If Base::~Base() is virtual, defined destruction prints Destructing Derived, then Destructing Base.

7. Virtual-function rules
Questions 1 to 4:
virtualenables runtime override selection.Questions 3, 5 and 8:
= 0makes a member pure virtual and its class abstract.Question 6: static members cannot be virtual.
Question 7: read
NOTbefore judging either statement.Question 11: a polymorphic base intended for deletion needs a virtual destructor.
If 1 to 4 went wrong, revise terminology. For 5 to 8, revise pure-virtual and member rules. For 9 to 11, trace static type, actual object, final overrider and destruction. Results: 25 for the virtual Base* example, B::fun() for Question 9, and C then B for Question 10. Use Coding For Placements for C++, coding-test and placement practice. Rerun Questions 9 to 11 on paper, then name each dispatch or lifetime rule.
Keep learning
Templates in C++: Reusable Parameterized Code with Worked Examples
Learn how one C++ template produces type-specific functions and classes. Follow exact calls, calculations, deduction failures, and practical corrections.
Friend Functions in C++: Controlled Class Access with a Worked Example
See how a non-member friend function can validate and update two Wallet objects while private balances stay hidden from ordinary callers. Includes runnable C++ and an exact trace.
Data Types in C++: Fundamental and Derived Types with Worked Examples
Learn how C++ fundamental types differ from arrays, pointers, references, and function types. Trace one complete program, then test the conversion traps.
C++ Constructors and Object Initialization: Techniques, Order and a Worked Trace
Learn how C++ chooses default, parameterised, delegating and copy constructors, then trace member states and initialization order through complete code.





