derived class accessibility

后端 未结 4 1745
有刺的猬
有刺的猬 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:22

    This way, it would be trivial to use a class marked as internal or private as if it were public, by just doing an empty override, just like you did in your example. This would defeat the purpose of marking classes anything other than public at all.

提交回复
热议问题