Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

About Virtual functions and their use ?

Answer Posted / sandeep

Virtual keyword is used to perform the dynamic binding
instead of early binding. To be brief below is the example

Class base
{
void display()
{
cout<<"in Base";
}
}
Class derived: public base
{
void display()
{
cout<<"in derived";
}
}
void main()
{
base* ptr;

ptr = new derived;
ptr->display();
}

When we execute above program output will be displayed as
"in base", but expected output was "in derived". So compiler
was choosing member function which matches the type of the
pointer rather than the member function which matches the
content of the pointer. But when we use Virtual keyword in
base class, it perform the dynamic binding, i.e., at run
time it choose the function to execute and executes "in
derived". So when we use virtual keyword, compiler will
select the member function which matches the content of the
pointer and it will ignore the member function which matches
the type of the pointer.

Is This Answer Correct ?    17 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How many variables do you need?

875


How Is The Dll Hell Problem Solved In .net?

972


Does c# have a 'throws' clause?

968


Explain acid rule of thumb for transactions in c#.

909


Explain the concepts of cts and cls(common language specification).

915


What Is The Smallest Unit Of Execution In .net?

886


How do I open the console window?

962


What is tryparse?

877


What is the use of delegate?

920


Can namespace contain the private class?

887


What is the extension of c# file?

918


How can I process command-line arguments?

918


What is boxing? Explain its functionality?

917


Write a C# program to find the Factorial of n

925


What is expandoobject in c#?

846