作者tkcn (小安)
站内java
标题Re: [J2SE] scjp考题
时间Sat Nov 17 14:25:34 2007
※ 引述《nf7series (真呆)》之铭言:
: 刚在作题库,有一题:
: 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,请问答案是对的吗?谢谢
答案没错
因为 class 的 access modifier 是 package
其他不同 package 的 class,连 target 这个 class 都看不到
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.114.78.239
1F:推 lightening:这种题目很没意思 这个答案的话 应该是指directly 11/17 21:27
2F:→ lightening:我看错了 XD 11/17 21:29
3F:推 louisyu:没有设定modifier,会预设为default,跟public是不同的 11/17 21:45
4F:→ nf7series:thanks... 11/18 17:49
5F:推 Elohim123:If a class has ‘no modifer’, then it CAN ONLY be a 02/09 16:51
6F:→ Elohim123:access from the same package 02/09 16:52