using system;
public class student
{
protected double Allow;
public double allowance1()
{
Allow = 100;
return Allow;
}
public virtual double allowance2()
{
Allow=1000;
return Allow;
}
}
public class PostGraduate : student
{
new public double allowance1()
{
Console.WriteLine("计算研究生的津贴:");
return 1.2 * base.allowance1();
}
public override double allowance2()
{
Console.WriteLine("计算研究生的津贴:");
return 1.2*base.allowance2();
}
}
public class Test
{
public static void Main()
{
student s = new student();
PostGraduate pg = new PostGraduate();
s = pg;
Console.WriteLine("该学生的津贴为:{0}",s.allowance1());
Console.WriteLine("该学生的津贴为:{0}",s.allowance2());
Console.WriteLine("该学生的津贴为:{0}", pg.allowance1());
Console.WriteLine("该学生的津贴为:{0}", pg.allowance2());
}
}
-------------------------------------------------------------------------------------------
我想请问下,第一个输出Console.WriteLine("该学生的津贴为:{0}",s.allowance1());
s.allowance1() 其中的pg已经把地址传给S了,可是为什么第一个输出还是调用基方法,而不是派生类的第一个方法