以下是给定的类:
interface IShape
{
void Draw();
}
class Rectangle : IShape
{
public void Draw() { }
}
class Square : Rectangle
{
public new void Draw() { }
}
有人能解释一下第二个Draw方法中发生了什么吗?
Rectangle rect = new Rectangle();
rect.Draw();
rect = new Square();
rect.Draw();
根据我的理解,应该会调用Square类的Draw方法,但是当我在VS2013中输入时,Rectangle类的Draw方法被调用了。