CoolInterview.com - World's Largest Collection of Interview Questions
Send Free SMS
 Interview Questions  
 Our Services  


INTERVIEW QUESTIONS LANGUAGES C++ DETAILS
Question :
What are virtual functions?
Category C++ Interview Questions
Rating (3.4) By 19 users
Added on 10/22/2004
Views 6268
Rate it!
Answers:

A virtual function allows derived classes to replace the implementation provided by the base class.
The compiler makes sure the replacement is always called whenever the object in question is actually of the derived class, even if the object is accessed by a base pointer rather than a derived pointer. This allows algorithms in the base class to be replaced in the derived class, even if users don't know about the derived class.



The virtual function is used in the case of multiple inheritance.consider a base and two derived classes.the two derived classes has its own plus the features of base class.again if we derive one more class from these two derived classes,the new derived class will have its own plus the featuresof the base class.but it will have two copies of the main base class.to avoid this we deive the base class as virtual.



 Posted by: Barkha Tardeja    

Contact Barkha Tardeja  Contact Barkha Tardeja

Virtual function means in order to achive runtime polymorphism and at run time compiler sud able to access the exact version of the function based on the type of object pointed to by base pointer.



 Posted by: Debashis     

Contact Debashis   Contact Debashis

virtual function is a function which is declared in the base class.and when base class inharited then this nirtual functions are redefine to fits its own needs.itis used as a form of interface



 Posted by: rohit    

Contact rohit  Contact rohit


If you have the better answer, then send it to us. We will display your answer after the approval.
Name :*
Email Id :*
Answer :*
Verification Code Code Image - Please contact webmaster if you have problems seeing this image code Not readable? Load New Code
Process Verification  Enter the above shown code:*
Inform me about updated answers to this question

   
Related Questions
View Answer
What is a scope resolution operator?
View Answer
What do you mean by inheritance?
View Answer
What is polymorphism? Explain with an example?
View Answer
What is the difference between an object and a class?
View Answer
What is encapsulation?
View Answer
What is abstraction?
View Answer
What do you mean by binding of data and functions?
View Answer
Difference between realloc() and free()?
View Answer
What is function overloading and operator overloading?
View Answer
What is virtual class and friend class?
View Answer

Please Note: We keep on updating better answers to this site. Subscribe to our newsletter to get notified when better answer is posted.

Notify me when better answer is posted!
Email:

View ALL C++ Interview Questions

User Options
Sponsored Links


Copyright ©2003-2010 CoolInterview.com, All Rights Reserved.
Privacy Policy | Terms and Conditions
Page URL: http://www.coolinterview.com/interview/954/default.asp?cachecommand=bypass


Download Yahoo Messenger | Placement Papers| FREE SMS | ASP .Net Tutorial | Web Hosting | Free SMS | Dedicated Servers | Joke of the Day

0.84