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
Explain the difference between a namespace and assembly name in .net?
How do I use the 'using' keyword with multiple objects?
What does using do in c#?
What is private in c#?
How to find Percentage, name ,College from a resume or document ? How to export these values to other page in C#?
what is generics? can u explain 5 to 6 examples on generics that covers class,method,structure,list,delegates?
What is a partial class in c#?
What is the difference between method overriding and method overloading?
How do I run a cshtml file?
What is the differences between datagrid, datalist and repeater in .net?
How can you set image source dynamically from c# application to ”test.png” file?
Is c# lazy thread safe?
What is generic and non generic collections in c#?
What are get and set in c#?
Is c# different than c++?