为什么一个类不能定义为受保护的? [英] Why can a class not be defined as protected?
本文介绍了为什么一个类不能定义为受保护的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么我们不能将类定义为protected
?
Why can we not define a class as protected
?
我知道我们不能,但为什么呢?应该有一些具体的原因.
I know that we can't, but why? There should be some specific reason.
推荐答案
因为没有意义.
受保护的类成员(方法或变量)就像包私有(默认可见性)一样,除了它也可以从子类访问.
由于在 Java 中没有子包"或包继承"这样的概念,因此声明类受保护或包私有是一回事.
Protected class member (method or variable) is just like package-private (default visibility), except that it also can be accessed from subclasses.
Since there's no such concept as 'subpackage' or 'package-inheritance' in Java, declaring class protected or package-private would be the same thing.
不过,您可以将嵌套类和内部类声明为受保护的或私有的.
You can declare nested and inner classes as protected or private, though.
这篇关于为什么一个类不能定义为受保护的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文