Can we call a function from derived class if you have one base class Virtual Function ?

 Posted by Chvrsri on 3/22/2011 | Category: C# Interview questions | Views: 3309 | Points: 40

Yes we can,

Using this code snippet we can understand that the virtual function(MyFunction) which is defined in the base class (hai) is called from the derived class (hello) which will return a value 1.

class hai

public virtual int MyFunction()
return 1;
class hello:hai
public int j()
return MyFunction();

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Posted by: on: 6/7/2011 | Points: 10
can u plz explain what is virtual method,how to use it in a class and what is the use of virtualmethod(TCS Interview question)
Posted by: Chvrsri on: 6/7/2011 | Points: 10
Sure, kindly post the same question in forum section so that it will help all the users.


Login to post response