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か?

4

2 に答える 2

2

呼び出しますInheritedClassInstance.AnotherMethod()

基本クラスを呼び出したい場合は、次のAnotherMethod()ように記述しますbase.AnotherMethod()

于 2011-04-14T17:37:26.823 に答える
0

基本メソッドを明示的に呼び出さない限り、継承されたクラスの派生メソッドを呼び出します ( base.AnotherMethod())

于 2011-04-14T17:38:05.140 に答える