我有点麻烦弄清楚这一点。
我的代码结构如下:
public class ParentClass
{
private double p_num;
public ParentClass()
{
}
public void AddSomething(double num)
{
System.Console.WriteLine(ParentNum + num);
}
public double ParentNum
{
set { p_num = value; }
get { return p_num; }
}
}
public class ChildClass : ParentClass
{
private double c_num;
public ChildClass()
{
}
public void AddSomething()
{
base.AddSomething(ChildNum);
}
public double ChildNum
{
set { c_num = value; }
get { return c_num; }
}
}
public class Test
{
public static void Main()
{
ParentClass p = new ParentClass();
ChildClass c = new ChildClass();
c.ChildNum = 8.0;
p.ParentNum = 5.0;
c.AddSomething();
}
}
这怎么会打印 8.0 而不是 13.0?