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

What is c-sharp (c#)?

729


Explain the types of comments in c#?

728


What is property in c#?

701


What is dynamic dispatch?

728


How can i Spawn a Thread

693


Why singleton class is sealed in c#?

704


What is verbatim string?

691


Why data types are important in c#?

691


Give an example of a ctype.

771


What is string in c# net?

691


Which programming language is best for desktop applications?

682


What is difference between ienumerable and list?

740


How do you set a class path?

638


write a C# Program add two matrix ?

759


What is sorted list in c#?

678