class MyClass
{
protected int num=0;
public int Num
{
set
{
num=value;
}
}
}
class MyClassDerived: MyClass
{
new public int Num
{
get
{
return num;
}
}
}
class Test
{
public static void Main()
{
MyClassDerived MyObject = new MyClassDerived();
//MyObject.Num= 1; //错误 !
((MyClass)MyObject).Num = 1;
}
}
abstract class A
{
int y;
public virtual int X
{
get { return 0; }
}
public virtual int Y
{
get { return y; }
set { y = value; }
}
public abstract int Z { get; set; }
}
class B: A
{
int z;
public override int X
{
get { return base.X + 1; }
}
public override int Y
{
set { base.Y = value < 0? 0: value; }
}
public override int Z
{
get { return z; }
set { z = value; }
}
}