C++ interview questions on virtual function and abstract class


What is a virtual function?

A virtual function is a method that does not have a definition when defined in the base class. This method is left black in the parent class and it is redefined in the child class.

What is an abstract class?

An abstract class is a class that has abstract members or at least one pure virtual function in its definition. An abstract class can never be instanced (creating an object). It can only be inherited and the methods could be overwritten.

Can there be any virtual Destructors?

Yes, These are legal in C++, but these are destructors are for base class instead of the child class.

Does every virtual function need to be overridden?

No, It is not always mandatory to redefine a virtual function. It can be used as it is in the base class.

Can we have a constructor as Virtual?

Constructors cannot be virtual, because they need to be defined in the class.

Updated on: 19-Sep-2019

909 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements