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
Can I use parseint?
Can a private virtual method can be overridden?
What is a web service in c#?
Why do we use ienumerable in c#?
What is data dictionary in c#?
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?
How many bytes is a long c#?
What is the use of getcommandlineargs() method in c#.net?
My switch statement works differently! Why?
What is a verbatim string literal and why do we use it?
Can class inherit from struct c#?
What is the difference between dynamic and var in c#?
What are the types in c#?
Is string nullable c#?
What is a partial method?