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 is a generic in c#?
what is the scope of anonymous type ?
What is better C# or VB.NET?
What is the output of TextWriterTraceListener redirected?
What is an assembly qualified name? Is it a filename? How is it different?
What is the benefit of dependency injection c#?
Whats an assembly? Describe the importance of assembly?
What is using keyword?
What is a property in c#?
Why abstract class is not instantiated in c#?
Can you pass value types by reference to a method?
Can you put two constructor with the same structure in a class?
What is COM Interoperability?
Explain publishers and subscribers in events.
Does a class need a constructor c#?