/*
* Created by sharpdevelop.
* User: noo
* Date: 2009-8-16
* Time: 16: 40
*
* Hide and override (the keywords are new and override respectively)
*/
Using system;
Class newa
{
Public Virtual void output1 ()
{
Console. writeline ("base class method 1 ");
}
Public void output2 ()
{
Console. writeline ("base class method 2 ");
}
}
Class newb: newa
{
Public override void output1 () // the corresponding base class method must use the virtual keyword. This method is called to override the base class method.
{
Console. writeline ("override base class method 1 ");
}
New public void output2 () // the corresponding base class method can be used without the virtual keyword. This method is called to hide the base class method.
{
Console. writeline ("hiding base class method 2 ");
}
}
Class Test
{
Static void main ()
{
Newb B = new newb ();
Newa;
A = B;
A. output1 (); // call the rewrite method in B
A. output2 (); // call the original method in
B. output1 (); // call the rewrite method in B.
B. output2 (); // call the hidden method in B.
Newa AA = new newa ();
AA. output1 (); // call the original method in
AA. output2 (); // call the original method in
}
}