Virtual-override example.

CGN007
Posted by CGN007 under C# category on | Points: 40 | Views : 1209
1.Base class
  public class BaseClass
{
public virtual int add()
{
return 10;
}

}


2.Child Class

  public class ChildClass : BaseClass
{
public override int add()
{
base.add();
return 12;
}

}



2.Calling the add() method in main()

 class Program
{
static void Main(string[] args)
{
//Creating ChildClass object
ChildClass childObj = new ChildClass();
//Calling the ChildClass add method
Console.WriteLine(childObj.add());

Console.ReadKey();
}
}

Comments or Responses

Login to post response