C# - Can publicly inherited methods be hidden (e.g. made private to derived class)

前端 未结 10 1672
说谎
说谎 2020-12-04 19:00

Suppose I have BaseClass with public methods A and B, and I create DerivedClass through inheritance.

e.g.

public DerivedClass : BaseClass {}
<         


        
10条回答
  •  无人及你
    2020-12-04 19:34

    If they're defined public in the original class, you cannot override them to be private in your derived class. However, you could make the public method throw an exception and implement your own private function.

    Edit: Jorge Ferreira is correct.

提交回复
热议问题