2011-04-14 87 views
0

我的情况解决方法是这样的:与基本类型

public class InheritedClass : BaseClass 
{ 
    public override void SomeMethod() 
    { 
     AnotherMethod(); 
    } 
    public override void AnotherMethod() 
    { 
    } 
} 

public class BaseClass 
{ 
    public virtual void SomeMethod() 
    { } 
    public virtual void AnotherMethod() 
    { } 
} 

那么哪种方法,当我打电话InheritedClassInstance.SomeMethod叫?它叫InheritedClassInstance.AnotherMethod还是BaseClass的AnotherMethod

回答

2

它调用InheritedClassInstance.AnotherMethod()

如果你想让它调用基类AnotherMethod()你会写base.AnotherMethod()

0

它将呼吁继承的类派生的方法,除非你明确地调用基方法(base.AnotherMethod()