- The virtual keyword signifies that method and property can be overridden.
- If the method of base class is not marked virtual, even then it can be overridden in derived class by marking it new.
E.g.: class Employee
{
protected double basic;
protected double gross;
public void CalcSal()
{
gross = basic + 0.5*basic;
}
}
class Manager : Employee
{
protected double allowances;
public new void CalculateSalary()
{
gross = basic + 0.5*basic + allowances;
}
}
virtual
Subscribe to:
Post Comments
(
Atom
)
0 comments :
Post a Comment