Run Time PolyMorphism Example1 For Beginner??????

Sabarimahesh
Posted by Sabarimahesh under C# category on | Points: 40 | Views : 1188
Class BaseClass consists of function Show().

Class DerivedClass hides the function Show()


class Program
{
static void Main(string[] args)
{
Baseclass bc;
bc = new Baseclass();
bc.Show();
Console.ReadLine();

}

}

class Baseclass
{
public void Show()
{
System.Console.WriteLine("Baseclass::Show");
}
}

class DerivedClass : Baseclass
{
new public void Show()
{
System.Console.WriteLine("DerivedClass::Show");
}
}



OutPut:


Baseclass::Show


. Show() of class BaseClass is executed because the reference variable b refers to the object of class BaseClass.

Comments or Responses

Posted by: Akiii on: 5/28/2012 Level:Bronze | Status: [Member] | Points: 10
Hi @Mahesh ......

What does the new keyword do here ?


Thanks and Regards
Akiii

Login to post response