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

What is the delegates in c#?

715


How to find methods of a assembly file (not using ILDASM)?

921


What is out int in c#?

688


What is a console operator?

687


Is string nullable in c#?

713


When should we use sealed class in c#?

708


Can var be null c#?

652


What is xor operator in c#?

737


What is the difference between interface and abstract class in c#?

699


Is it possible to have a static indexer in c#?

745


What is task parallel library?

753


explain the nature of the assembly work?

2341


What is a dictionary in c#?

701


When can a derived class override a base class member?

711


What is difference between Trace and Debug

804