Using virtual and override keywords in C#.net
Here the method name is same and the number as well as the type of the argument is the same. So, while executing which method is called first is to be determined at run time. For that we have to use two key words like virtual and override.
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication14
{
class Shape
{
public virtual void Draw()
{
Console.WriteLine("Drawing Shape...");
}
}
class Circle : Shape
{
public override void Draw()
{
Console.WriteLine("Drawing Circle...");
}
static void Main()
{
Shape theShape = new Circle();
theShape.Draw();
}
}
}
No comments:
Post a Comment