GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Programming  >  C++
Go To First  |  Previous Question  |  Next Question 
 C++  |  Question 6 of 203    Print  
What are virtual functions?
 
 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. 
 


  
Total Answers and Comments: 4 Last Update: June 12, 2009   
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: Himanshu Mendiratta
 
C++ virtual function is a member function of a class, whose functionality can be over-ridden in its derived classes. 
C++ virtual function is, 
 
* A member function of a class 
* Declared with virtual keyword 
* Usually has a different functionality in the derived class 
* A function call is resolved at run-time 


Above answer was rated as good by the following members:
ozkan, amavi
August 30, 2005 07:54:48   #1  
Himanshu Mendiratta        

RE: What are virtual functions?  
C++ virtual function is a member function of a class whose functionality can be over-ridden in its derived classes.
C++ virtual function is

* A member function of a class
* Declared with virtual keyword
* Usually has a different functionality in the derived class
* A function call is resolved at run-time

 
Is this answer useful? Yes | NoAnswer is useful 2   Answer is not useful 0Overall Rating: +2    
August 30, 2005 15:25:27   #2  
Pravesh Kumar        

RE: What are virtual functions?  
C++ virtual functions are used to acheive run time polymorphism. To declare a virtual function virtual keyword is put at the start of normal function declaration.
Requirements for implementing virtual function-
[/LIST]
* Base Class Pointer
* Inheritance
* Method Overriding.

 
Is this answer useful? Yes | No
October 04, 2005 08:59:01   #3  
bhuvana        

comment

A virtual function allows derived classes to replace the implementation provided by the base class.


 
Is this answer useful? Yes | No
June 12, 2009 08:31:50   #4  
gunjan.chandra Member Since: April 2009   Contribution: 7    

RE: What are virtual functions?  
It is a functions whose behaviour can be overriden with an inherited class by a function of same signature. It is an important part of OOPS and Polymorphism.
 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape