Is it possible to override a hidden method?

Let's say I have the following hierarchy:

public class MyClass
{
  protected virtual void Method() { ... }
}

public class MySubClass : MyClass
{
  public new virtual void Method() { ... }
}

public class MySubSubClass : MySubClass
{
  // how do I reference the protected Method() to override it?
}

Is it possible to override the implementation of the protectedMethod () method so that calls from other methods defined in MyClass are sent to the implementation in MySubSubClass?

If this is not possible, it would be nice to enlighten why.

+3
source share
4 answers

If you are trying to override the method version defined in MyClass, then you cannot answer. A definition in MySubClasshides this implementation from you, and you cannot override it.

+7
source

, , :

public new virtual void Method()
+1

. "" , . "newed" .

Method(), MyClass, MySubSubClass, , , MySubSubClass

0

@Jared, . , new , virtual. - public new Method() - . new , , -.

0
source

Source: https://habr.com/ru/post/1724694/


All Articles