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


Please Help Members By Posting Answers For Below Questions

Explain the difference between a namespace and assembly name in .net?

581


How do I use the 'using' keyword with multiple objects?

598


What does using do in c#?

592


What is private in c#?

567


How to find Percentage, name ,College from a resume or document ? How to export these values to other page in C#?

606






what is generics? can u explain 5 to 6 examples on generics that covers class,method,structure,list,delegates?

1527


What is a partial class in c#?

563


What is the difference between method overriding and method overloading?

549


How do I run a cshtml file?

585


What is the differences between datagrid, datalist and repeater in .net?

568


How can you set image source dynamically from c# application to ”test.png” file?

716


Is c# lazy thread safe?

571


What is generic and non generic collections in c#?

511


What are get and set in c#?

664


Is c# different than c++?

595