[J2SE] 變數 scope 問題

看板java作者 (真呆)時間18年前 (2007/11/17 14:14), 編輯推噓4(401)
留言5則, 3人參與, 最新討論串1/1
剛在作題庫,有一題: Given : package test; class target { public String name="hello"; } what can directly access and change the value of the variable name? A.any class B.only the Target class C.any class in the test package D.any class that extends Target 結果答案是C 我以為是A,請問答案是對的嗎?謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 203.73.98.93

11/17 14:40, , 1F
target 不是 public class, 這是原因
11/17 14:40, 1F

11/18 10:19, , 2F
同上原因 不過我覺得答案應該是B= =
11/18 10:19, 2F

11/18 13:53, , 3F
可是 Target class 不存在 XD
11/18 13:53, 3F

11/18 17:48, , 4F
B應該是target class才對
11/18 17:48, 4F

11/18 17:48, , 5F
謝拉 這樣我就懂了
11/18 17:48, 5F
文章代碼(AID): #17FeRIyP (java)