Which of the following is not correct for a virtual function in C++?

2017

Which of the following is not correct for a virtual function in C++?

  1. A.

    Virtual functions can be declared in public, protected, or private sections of a class.

  2. B.

    A virtual function can be static.

  3. C.

    Virtual functions can be accessed using pointers or references.

  4. D.

    A virtual function is declared in a base class so derived classes can override it.

Attempted by 137 students.

Show answer & explanation

Correct answer: B

Key idea: Virtual dispatch works on object instances. Static member functions belong to the class, not to an object instance.

Therefore, a static member function cannot be virtual in C++.

The other statements are true: a virtual function may be placed under any access specifier, is commonly called through a base-class pointer or reference, and is declared in a base class for overriding.

Final answer: Option B

Explore the full course: Mppsc Assistant Professor