About Virtual functions and their use ?

Answer Posted / deepak jindal

If a base class method is to be overriden, It is defined
using virtual keyword. You need to use the override keyword
in order to re-implement the virtual method. Exp:

public class Employee
{
public virtual void SetBasic(float money) //This method may
be overriden
{ Basic += money; }
}


public class Manager : Employee
{
public override void SetBasic(float money) //This method is
being overriden
{
float managerIncentive = 10000;
base.SetSalary(money + managerIncentive); //Calling base
class method
}
}

Is This Answer Correct ?    14 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can I use parseint?

472


Can a private virtual method can be overridden?

551


What is a web service in c#?

577


Why do we use ienumerable in c#?

477


What is data dictionary in c#?

483






If the interface in c# only contains the declaration of the methods and we need to define those methods in the class, then why we use the interface?

555


How many bytes is a long c#?

457


What is the use of getcommandlineargs() method in c#.net?

501


My switch statement works differently! Why?

507


What is a verbatim string literal and why do we use it?

471


Can class inherit from struct c#?

507


What is the difference between dynamic and var in c#?

454


What are the types in c#?

494


Is string nullable c#?

490


What is a partial method?

488