create Circle and Triangle class by inheriting the Shape Class. Both the inherited classes
should override the WhoamI() method of the Shape Class.
public class Shape
{
private void WhoamI()
{
Console.WriteLine("I m Shape");
}
}
class Triangle : public Shape
{
public virtual void WhoamI()
{
Console.WriteLine("I m Triangle");
}
}
public class Circle : public Shape
{
void WhoamI()
{
Console.WriteLine("I m Circle");
}
}
class Program
{
static void Main(string[] args)
{
Shape s;
s = new Triangle();
s.WhoamI();
s = new Circle();
s.WhoamI();
Console.ReadKey();
}
}
Comments
Leave a comment