请教两道SCJP的模拟题

child_bj child_bj 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
是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不应该对,成员变量不能没有途径访问吧。还是
...全文
评论 5
收藏 已收藏
分享
返回顶部
child_bj
Java 51,407 成员 86,126 内容