Open In App

UGC-NET | UGC-NET CS 2017 Dec 2 | Question 14

Last Updated : 15 Mar, 2018
Like Article
Like
Save
Share
Report

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

(A)

Must be declared in public section of class.

(B)

Virtual function can be static.

(C)

Virtual function should be accessed using pointers.

(D)

Virtual function is defined in base class.



Answer: (B)

Explanation:

(B) Virtual functions cannot be declared as static. Static member functions in C++ do not participate in dynamic binding (polymorphism), which is a fundamental feature of virtual functions. Static functions are resolved at compile time based on the type of the pointer or reference, whereas virtual functions are resolved at runtime based on the actual type of the object they’re invoked on.

So, the correct choice is (B) Virtual function can be static.


Quiz of this Question
Please comment below if you find anything wrong in the above post


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads