看板 java 關於我們 聯絡資訊
想問一下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)
adrianshum:因為該 inner class 本身的 accessibilty 是 default 11/25 21:33
nf7series:對厚,挨,上次也問了一個一樣的問題,這次還錯 11/25 23:35