作者nf7series (真呆)
看板java
标题[问题] 内隐类别的存取
时间Sun Nov 25 20:56:11 2007
想问一下scjp的考题:
Given:
package geometry;
public class Hypotenuse
{
public InnerTriangle it=new InnerTriangle();
class InnerTriangle
{
public int base;
publuc int height;
}
}
Which statement is true about the class of an object that can
reference the variable base?
A.It can be any class.
B.No class has access to base.
C.The class must belong to the geometry package.
D.The class must be a subclass of the class Hypotenuse.
答案是C,但是我还是不太懂
书上是写说要执行内隐类别的唯一方式,便是使用外部类别的实体
那不就是能使用到Hypotenuse的类别都能存取base吗?
他是public的class,别的package的类别也能存取到阿,答案怎会是C?
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 203.73.98.93
※ 编辑: nf7series 来自: 203.73.98.93 (11/25 20:59)
1F:推 adrianshum:因为该 inner class 本身的 accessibilty 是 default 11/25 21:33
2F:推 nf7series:对厚,挨,上次也问了一个一样的问题,这次还错 11/25 23:35