what is virtual function?
Answers were Sorted based on User's Feedback
Answer / jayakrishna reddy
The virtual keyword means that method,property or function
can be overridden
| Is This Answer Correct ? | 154 Yes | 24 No |
Answer / manab
When derived class overrides the base class method by
redefining the same function, then if client wants to
access redefined the method from derived class through a
pointer from base class object, then you must define this
function in base class as virtual function.
| Is This Answer Correct ? | 68 Yes | 7 No |
Answer / manav sharma
It allows one to write generalized code that works with the
base class pointer which can dynamically point to the
derieved class objects. Virtual function allows you to
implement runtime polymorphism. It allows the function call
to be binded with function definition as late as runtime.
Also read: concept of VPTR and VTABLE from Thinking in C++
| Is This Answer Correct ? | 56 Yes | 8 No |
Answer / aarti ashar
A virtual function is a function member of a class,
declared using the "virtual" keyword. A pointer to a
derived class object may be assigned to a base class
pointer, and a virtual function called through the pointer.
If the function is virtual and occurs both in the base
class and in derived classes, then the right function will
be picked up based on what the base class pointer "really"
points at.
| Is This Answer Correct ? | 25 Yes | 6 No |
Answer / nk
A virtual function is basically a like normal function but
we can override the function in the derived classes.
Now when we want to access like (fn)
Base * bptr = new Derived();
bptr->fn(); then function of the derived class will be
called only if the function is marked as virtual in the
base class.
i.e the virtual keywork tells to use the function of the
class to which it is pointing to and not to the Base class.
This is called runtime polymorphism.
| Is This Answer Correct ? | 24 Yes | 7 No |
Answer / laxmikant
A virtual function is a function which is precedded by the
key word derived is declared in the base class.It is
normally used to achieve run time polymerphism.That means
we can override the base class function in the derived
class.We can invoke the virtual function through the base
class pointer depending upon the contents to which the base
class pointer points to.
Generally the implementation of virtual
class was found in inheritance where the base class
function is override in the derived class.
| Is This Answer Correct ? | 23 Yes | 6 No |
Answer / shekhar
virtual function is used to prevent from more times
calling.That means if a function is declared as virtual
then its def will be diferent in base class & derived class
| Is This Answer Correct ? | 11 Yes | 0 No |
Answer / m.ahmad
Virtual function means the function which is use in base class
and also use in drive class with same name and same arguments
then we use a keyword virtual with base class.
| Is This Answer Correct ? | 12 Yes | 1 No |
Answer / gomathisivaram
The virtual function is nothing but the function in the
base class with the virtual keyword, that allows us to
derive only once in the class which is going to accsess it
while it is the child of two different classes which are
the child of the same base class.This is nothing but the
dynamic binding.
| Is This Answer Correct ? | 18 Yes | 10 No |
Question: Write a program that prints a paycheck. Ask the program user for the name of the employee, the hourly rate, and the number of hours worked. If the number of hours exceeds 40, the employee is paid “time and a half”, that is, 150 percent of the hourly rate on the hours exceeding 40. Be sure to use stepwi se refine ment and break your solution into several functions. Use the int_name function to print the dollar amount of the check.
What is overriding vs overloading?
What is Hashing and how is it done? Pictorial form?
Which is not an object oriented programming language?
What is R T T I ?
How many types of access specifier in c# and vb.net?
What is extreme programming?
Write a program to implement OOPS concepts such as inheritance, polymorphism, friend function, operator overloading?
Difference between new operator and operator new
What does no cap mean?
//what is wrong with the programme?? #include<iostream.h> template <class first> class dd { first i; public: void set(); void print(); }; void dd< first>:: set() { cin>>i; } void dd< first>::print() { cout<<"\n"<<i; } void main() { dd <char>g; g.set(); g.print(); }
What is data binding in oops?