假设Vehicle类包含一个名为CalculateMaxSpeed的虚方法。假设MotorVehicle和Automobile类都覆盖了这个方法。在执行下面代码的第二条语句时,哪个类定义的方法被调用?
Vehicle类(Automobile的祖先类)> MotorVehicle类(Auatomobile的父类)> Automobile类
Vehicle类(Automobile的祖先类)> MotorVehicle类(Auatomobile的父类)> Automobile类
MotorVehicle car = new Automobile();
car.CalculateMaxSpeed();
在我看来应该是Automobile#CalculateMaxSpeed
,但我担心它可能是MotorVehicle#CalculateMaxSpeed
,因为MotorVehicle
包含Automobile
的实例。请有经验的人解释一下。