what is virtual function in c++

Answer Posted / b.balaganesan

Virtual, as the name implies, is something that exists in
effect but not in reality. The concept of virtual function
is the same as a function, but it does not really exist
although it appears in needed places in a program. The
object-oriented programming language C++ implements the
concept of virtual function as a simple member function,
like all member functions of the class.

Need for Virtual Function:

The vital reason for having a virtual function is to
implement a different functionality in the derived class.

For example: a Make function in a class Vehicle may have to
make a Vehicle with red color. A class called FourWheeler,
derived or inherited from Vehicle, may have to use a blue
background and 4 tires as wheels. For this scenario, the
Make function for FourWheeler should now have a different
functionality from the one at the class called Vehicle.
This concept is called Virtual Function.

Is This Answer Correct ?    10 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are oops functions?

594


Describe these concepts: Polymorphism, Inheritance and Abstraction.

622


What does and I oop mean in text?

638


What is object and class in oops?

596


Where You Can Use Interface in your Project

1437






What is class in oop with example?

631


write knight tour problem which is present in datastructure

2175


What is encapsulation in oops?

547


what type of questions

1701


What is multilevel inheritance?

734


Write a program to reverse a string using recursive function?

1804


write string class as your own class in java without using any built-in function

1984


What is a function in oop?

639


What is encapsulation c#?

613


What is overriding in oops?

614