C++ | Virtual Functions | Question 11

Can static functions be virtual? Will the following program compile?

filter_none

edit
close

play_arrow

link
brightness_4
code

#include<iostream> 
using namespace std;    
 
class Test
{
   public:
      virtual static void fun()  { }
};

chevron_right


(A) Yes
(B) No


Answer: (B)

Explanation: Static functions are class specific and may not be called on objects. Virtual functions are called according to the pointed or referred object.

Quiz of this Question

GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details

My Personal Notes arrow_drop_up