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
What do you know about device context?
Why use a singleton instead of static methods?
Can a class be private in c#?
Why is it called c sharp?
What is difference between Enum and Struct?
Can we declare class as protected?
What is an int in c#?
Why we use oops in c#?
Can we extend sealed class in c#?
Is int an object in c#?
what is the scope of anonymous type ?
What are circular references? How garbage collection deals with circular references.
How long can loop recorders stay in?
What are delegates in C#?
What are the value types in c#?