derived class accessibility

后端 未结 4 1782
有刺的猬
有刺的猬 2021-01-04 13:49

Why in C# it is not allowed for derived classes to have greater accessibility than its base class.

For example this will give error : Inconsistent accessibility: bas

4条回答
  •  自闭症患者
    2021-01-04 14:31

    internal is not the same as package private in Java. The user of DerivedClass may not have or have access to the DLL that BaseClass is in so DerivedClass can't depend on it. Package privacy is a much looser concept in Java - but in your example, DerivedClass would have to be in the same package as BaseClass so there's a good chance the client user would have both of those classes so Java allows it.

提交回复
热议问题