//Method Overriding
using System;
public class Rect
{
public virtual void getArea()
{
Console.WriteLine(" Rect");
}
}
public class Square : Rect
{
public override void getArea()
{
Console.WriteLine("Square ");
}
}
class TestClass
{
public static void Main()
{
Square sq = new Square();
Rect r = sq;
r.getArea();
sq.getArea();
}
}
below 'll be the 0/p
Square
Square
//Method Hiding
using System;
public class Rect
{
public virtual void getArea()
{
Console.WriteLine(" Rect");
}}
public class Square:Rect
{
public new void getArea()
{
Console.WriteLine("Square ");
}
}
class TestClass
{
public static void Main()
{
Square sq = new Square();
Rect r = sq;
r.getArea();
sq.getArea();
}
}
below 'll be the 0/p
Rect
Square
No comments:
Post a Comment