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
Are c# objects passed by reference?
What do you mean by expression tree?
What is mvc firstordefault?
What is difference between .net and c#?
What is the use of GC.KeepAlive Method?
What is system predicate?
What are annotations in c#?
What is uint64?
What are the different states of a thread?
What is xaml in c#?
Illustrate the differences between the system.array.copyto() and system.array.clone()?
Can a class be private in c#?
Are classes passed by reference in c#?
Explain Constructor and destructor?
What is the usage of transponders?