Virtual Functions and Dynamic Binding – MCQs July 22, 2025 by u930973931_answers 30 Score: 0 Attempted: 0/30 Subscribe 1. : What is the primary purpose of a virtual function in C++? (A) To allow function overloading (B) To support multiple inheritance (C) To enable dynamic binding (D) To increase performance 2. : What keyword is used to declare a virtual function in C++? (A) static (B) public (C) friend (D) virtual 3. : Which type of function is resolved at runtime in C++? (A) Normal function (B) Friend function (C) Static function (D) Virtual function 4. : Which type of binding does a virtual function implement? (A) Static binding (B) Compile-time binding (C) Early binding (D) Late binding 5. : Where is the virtual table (vtable) created? (A) During compilation (B) At runtime (C) In the source code (D) In the constructor 6. : What must be present in the base class for dynamic binding to occur? (A) Constructor (B) Destructor (C) Virtual function (D) Static function 7. : Which of the following does NOT support dynamic binding? (A) Virtual function (B) Static member function (C) Function pointer (D) Overridden function 8. : What happens if a virtual function is not overridden in the derived class? (A) Compiler error (B) Base class version is invoked (C) Program crashes (D) Nothing happens 9. : What is dynamic polymorphism achieved through in C++? (A) Function overloading (B) Operator overloading (C) Virtual functions (D) Inline functions 10. : What type of function can be declared virtual? (A) Non-member functions (B) Global functions (C) Member functions (D) Static functions 11. : Can a constructor be virtual in C++? (A) Yes (B) No (C) Only in abstract classes (D) Only in derived classes 12. : Which mechanism allows calling the appropriate function version using a base class pointer? (A) Function overloading (B) Static binding (C) Dynamic binding (D) Inline expansion 13. : What ensures that destructors are properly called in a class hierarchy? (A) Static destructors (B) Virtual destructors (C) Inline destructors (D) Overloaded destructors 14. : Can a destructor be virtual in C++? (A) No (B) Yes (C) Only if there’s no constructor (D) Only in the base class 15. : What is the benefit of virtual destructors? (A) Speed up execution (B) Allow constructor overloading (C) Ensure correct object cleanup (D) Enable template specialization 16. : What is the default behavior of a virtual function? (A) Inline expansion (B) Runtime linking (C) Static allocation (D) Compile-time checking 17. : How do you make a class abstract in C++? (A) By using a static function (B) By declaring a virtual constructor (C) By including a pure virtual function (D) By using friend functions 18. : What is the syntax for a pure virtual function? (A) virtual void show(); (B) virtual void show() = 0; (C) pure virtual void show(); (D) static virtual void show(); 19. : What happens if an abstract class is instantiated? (A) Compilation error (B) Object is created (C) Undefined behavior (D) Runs successfully 20. : What is the correct term for “virtual functions resolved at runtime”? (A) Static dispatch (B) Inline dispatch (C) Dynamic dispatch (D) Template dispatch 21. : In which memory area is the virtual table stored? (A) Stack (B) Heap (C) Static segment (D) Data segment 22. : Which one is true about virtual tables? (A) Each class has its own (B) All objects share one (C) Created during compilation (D) Stored in stack 23. : What determines the function called in dynamic binding? (A) The class of the pointer (B) The type of the pointer (C) The type of the object (D) The name of the function 24. : What happens if a virtual function is called in a constructor? (A) Base class version is called (B) Derived class version is called (C) Compiler error (D) Runtime error 25. : What keyword is used to prevent further overriding of a virtual function? (A) protected (B) static (C) final (D) override 26. : Can virtual functions be private? (A) No (B) Yes (C) Only protected (D) Only in base class 27. : Which feature of OOP uses virtual functions? (A) Abstraction (B) Encapsulation (C) Polymorphism (D) Inheritance 28. : What is a vtable pointer called in C++ objects? (A) static pointer (B) class pointer (C) this pointer (D) vptr 29. : What must be the return type of a virtual function? (A) int only (B) Any valid type (C) void only (D) static 30. : Which of the following can’t be virtual? (A) Member functions (B) Destructor (C) Constructor (D) Overridden function