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
How do you encapsulate in c#?
Can a method be sealed in c#?
can you declare an override method to be static if the original method is not static?
Are value types sealed?
What is session c#?
Can we have 2 main methods in c#?
List the 5 different access modifiers in c#?
What is hashset c#?
What is string programming language?
What does question mark mean in c#?
What’s thread.sleep() in threading ?
What is call back method?
What is an abstract class c#?
How many digits is a 32 bit number?
What is executereader in c#?