C#.NET中的隐藏和重写2(关键字new和override)
/*
* Created by SharpDevelop.
* User: noo
* Date: 2009-8-16
* Time: 17:10
*
* 隐藏和重写2
*/
using System ;
class naoA
{
public virtual void output()
{
Console.WriteLine ("基类方法");
}
}
class naoB:naoA
{
public override void output()//注意重写和隐藏只能选用一个
{
Console.WriteLine ("重写方法");
}
// new public void output()
// {
// Console.WriteLine ("隐藏方法");
// }
}
class Test
{
static void Main()
{
naoB b=new naoB ();
b.output ();
}
}
* Created by SharpDevelop.
* User: noo
* Date: 2009-8-16
* Time: 17:10
*
* 隐藏和重写2
*/
using System ;
class naoA
{
public virtual void output()
{
Console.WriteLine ("基类方法");
}
}
class naoB:naoA
{
public override void output()//注意重写和隐藏只能选用一个
{
Console.WriteLine ("重写方法");
}
// new public void output()
// {
// Console.WriteLine ("隐藏方法");
// }
}
class Test
{
static void Main()
{
naoB b=new naoB ();
b.output ();
}
}