Which of the following is NOT correct about virtual functions in C++? I. A…
2021
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
Attempted by 151 students.
Show answer & explanation
Correct answer: D
Key idea
A virtual function in C++ is a member function declared with the virtual keyword, usually in a base class.
Statement check
Statement I: Correct. A non-member or global function cannot be declared virtual.
Statement II: Correct. Dynamic binding is commonly achieved by calling the virtual function through a base-class pointer or reference.
Conclusion
Both statements are correct, so no listed statement is “NOT correct.”
Final answer: Neither I nor II.