请教两道SCJP的模拟题

child_bj 2003-09-24 10:48:39
是104或者147里的。题目如下:
1.
Given:
1. public class SyncTest {
2. private int x;
3. private int y;
4. public synchronized void setX (int i) (x=1;)
5. public synchronized void setY (int i) (y=1;)
6. public synchronized void setXY(int 1)(set X(i); setY(i);)
7. public synchronized Boolean check() (return x !=y;)
8. )
Under which conditions will check () return true when called from a different class?
A. Check() can never return true.
B. Check() can return true when setXY is called by multiple threads.
C. Check() can return true when multiple threads call setX and setY separately.
D. Check() can only return true if SyncTest is changed to allow x and y to be set separately.

Answer: A
这道题,我觉得A也不对。答案却是A,为什么?是不是答案错了?高手帮忙解释一下!

2.
which two are true to describe an entire encapsulation class?
A. member data have no access modifiers
B. member data can be modified directly
C. the access modifier for methods is protected
D. the access modifier to member data is private
E. methods provide for access and modification of data

Answer: d,e
我觉得D不应该对,成员变量不能没有途径访问吧。还是
...全文
63 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
alexlex 2003-09-25
  • 打赏
  • 举报
回复
第一题选C

讨论看这里
http://expert.csdn.net/Expert/topic/2273/2273603.xml?temp=8.204287E-02
alexlex 2003-09-25
  • 打赏
  • 举报
回复
第二题的意思是选体现封装性的描述

而D说的是成员数据都应该声明为private
e是应该使用成员函数来访问私有的成员数据

标准的类都是这样设计的,只能用规定的方法访问和操作数据
child_bj 2003-09-25
  • 打赏
  • 举报
回复
不会吧,没有人知道呀!还是嫌弃分少?
child_bj 2003-09-24
  • 打赏
  • 举报
回复
楼上,你说的那道题也有,但是着道不是那道。
也谢谢你!
hbzx 2003-09-24
  • 打赏
  • 举报
回复
1.题目不对 应该是
1. public class SyncTest {
2. private int x;
3. private int y;
4. private synchronized void setX (int i) {x=1;}
5. private synchronized void setY (int i) {y=1;}
6. public void setXY(int i){setX(i); setY(i);}
7. public synchronized boolean check() {return x != y;}
8. }

选B

50,528

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧