- 论坛徽章:
- 0
|
以下是jvm spec 中的内容
A protected member of an object may be accessed only by code responsible for the implementation of that object. To be precise, a protected member may be accessed from anywhere in the package in which it is declared and, in addition, it may be accessed from within any declaration of a subclass of the class type that contains its declaration, provided that certain restrictions are obeyed.
访问控制也就是控制对其访问者的可见性。
由我上面引用的jvm spec 中可以看出protected修饰的方法在包内任何地方可见,或子类可见。
而你举的例子里面 检查的是该方法是否在外包中的子类中创建的父类对象的可见性,而不是子类中该方法的可见性.
[ 本帖最后由 白色乌鸦 于 2006-8-4 12:25 编辑 ] |
|