Thursday, July 12, 2007

Polymorphism Example 4

class A
{
public virtual void Print()
{
Console.WriteLine("We are in Class A.");
}
}
class C : A
{
public new void Print()
{
Console.WriteLine("We are in Class C.");
}
}
class Program
{
static void Main(string[] args)
{
A a = new A();
a.Print();
Console.ReadKey();
C c = new C();
c.Print();
Console.ReadKey();
A aa = new C();
aa.Print();
Console.ReadKey();
A aaa = (A)c;
aaa.Print();
Console.ReadKey();
//C ccc = (C)a;
//ccc.Print();
//Console.ReadKey();
}
}

No comments: