高分求JAVA面试答案!

时间:2022-10-03 19:07:32
1   .Which statement is true?
A. An anonymous inner class may be declared as final
B. An anonymous inner class can be declared as private
C. An anonymous inner class can implement multiple interfaces 
D. An anonymous inner class can access final variables in any enclosing scope
E. Construction of an instance of a static inner class requires an instance of the enclosing outer class



2.   Which statement is true?
A. If only one thread is blocked in the wait method of an object, and another thread executes the notify method on that same object , then the first thread immediately resumes execution.()
B. If a thread is blocked in the wait method of an object, and another thread executes the notify method on the same object, it is still possible that the first thread might never resume execution.
C. If a thread is blocked in the wait method of an object, and another thread executes the notify method on the same object, then the first thread definitely resumes execution as a direct and sole consequence of the notify call.
D. If two threads are blocked in the wait method of one object , and another thread executes the notify method on the same object, then the thread that executed the wait call first definitely resumes execution as a direct and sole consequence of the notify call.


3.    Which two cannot directly cause a thread to stop executing?
A. exiting from a synchronized block
B. calling the wait method on an object 
C. calling the notify method on an object 
D. calling a read method on an InputStream object
E. calling the setPriority method on a thread object


4. Given:
public class SyncTest{
    private int x;
private int y;
public void setX(int I){x=I;}
public void setY(int I){y=I;}
public synchronized void setXY(int I){setX(i);setY(i);}
public synchronized boolean check(){return x != y;}
}

Under which conditions will check() return true when called from adifferent 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 SynchTest is changed to allow x and y to be set separately.

30 个解决方案

#1


等高手来!

#2


第一个选:B
后边的不确定,我试验一下

#3


第三个也是选B,我确定

#4


我觉得第一个D

#5


第二个B

#6


i think the last one the correct answer should be B.

#7


第三题感觉CE

#8


最后一个当然是C

#9


D,A,B,C

#10


sorry misunderstanding the statement.... last one should be C

#11


1)D.  B不对,内部匿名类不能指定名字,当然不能指定private了。
2)B.
3)E肯定选,c,d不确定,ab肯定措。
4)C.

#12


to:treeroot
最后一个为什么选C?(这个答案是正确的)
第一个我错了,忘了annonymous了

#13


最后一个选B,看错了

#14


C答案中,多线程不多线程没关系,因为各自调用setx, sety两个没有synchronize的方法,完全有可能赋不同的值

#15


我觉得第三个选:AC
第四个C肯定正确,为什么B不对?

#16


mark

#17


我的答案
D
B
C、E
C

#18


--“第四个C肯定正确“
to: wjsfr(令狐葱)  为什么呢?

#19


to sunzq13(陡金山)
在多线程环境下,对于每个对象,synchronized方法只允许一个线程调用,这样setXY只能由一个线程访问,所以该对象的x、y变量值一定相同,而setX和setY不是同步方法,允许不同的线程同时访问,这时对象的x、y变量值不一定相同,所有check() 方法会返回true。

#20


up

#21


收藏一下

#22


1:c
2: b
3: b, d
4: c

#23


不是A就是B,再么就是C,也可能是D,或者是E。

#24


樓主在結貼時可以統計個正確的答案出來,

#25


我对我的答案负责:
第1题:A:这是常识,同时你可以实践得到该结果-------------An anonymous inner class may be declared as final
第2题:B:线程排列其实就是一个队列,能不能激活第一个线程只能看计算机的随机(同级)和优先级。
第3题:D、E :线程退出当然要停止了,所以A不行,等待也要停止执行,所以B不行,唤醒方法,当然要把自己阻塞了!所以C不行!
第4题:C ,考的是线程概念,B答案肯定不行,因为在多线程中,一旦调用:setXY(int I)方法,X,Y将相等;A、C、D答案都是相互排斥的,所以C答案对:如果setX和setY独立运行,check()可以返回TRUE。
答案已经得出,请楼主派分!谢谢拉!呵呵!

#26


#27


return x != y;我晕 看成return x == y;了

#28


免费申请二级域名
地址:http://www.nocoer.com        

注册的用户可以免费申请二级域名!               

申请后,只要在电子简历当中填写自己的个人资料!就可以通过访问二级域名来访问您的简历                

喜欢web开发的朋友多过来注册吧!               

让我们一起构造一个最庞大的人才库

#29



1 A
2 B
3 C E
4 B

胡乱添了一下,挺难的

#30


考把 x!=y错了
4: C 

#1


等高手来!

#2


第一个选:B
后边的不确定,我试验一下

#3


第三个也是选B,我确定

#4


我觉得第一个D

#5


第二个B

#6


i think the last one the correct answer should be B.

#7


第三题感觉CE

#8


最后一个当然是C

#9


D,A,B,C

#10


sorry misunderstanding the statement.... last one should be C

#11


1)D.  B不对,内部匿名类不能指定名字,当然不能指定private了。
2)B.
3)E肯定选,c,d不确定,ab肯定措。
4)C.

#12


to:treeroot
最后一个为什么选C?(这个答案是正确的)
第一个我错了,忘了annonymous了

#13


最后一个选B,看错了

#14


C答案中,多线程不多线程没关系,因为各自调用setx, sety两个没有synchronize的方法,完全有可能赋不同的值

#15


我觉得第三个选:AC
第四个C肯定正确,为什么B不对?

#16


mark

#17


我的答案
D
B
C、E
C

#18


--“第四个C肯定正确“
to: wjsfr(令狐葱)  为什么呢?

#19


to sunzq13(陡金山)
在多线程环境下,对于每个对象,synchronized方法只允许一个线程调用,这样setXY只能由一个线程访问,所以该对象的x、y变量值一定相同,而setX和setY不是同步方法,允许不同的线程同时访问,这时对象的x、y变量值不一定相同,所有check() 方法会返回true。

#20


up

#21


收藏一下

#22


1:c
2: b
3: b, d
4: c

#23


不是A就是B,再么就是C,也可能是D,或者是E。

#24


樓主在結貼時可以統計個正確的答案出來,

#25


我对我的答案负责:
第1题:A:这是常识,同时你可以实践得到该结果-------------An anonymous inner class may be declared as final
第2题:B:线程排列其实就是一个队列,能不能激活第一个线程只能看计算机的随机(同级)和优先级。
第3题:D、E :线程退出当然要停止了,所以A不行,等待也要停止执行,所以B不行,唤醒方法,当然要把自己阻塞了!所以C不行!
第4题:C ,考的是线程概念,B答案肯定不行,因为在多线程中,一旦调用:setXY(int I)方法,X,Y将相等;A、C、D答案都是相互排斥的,所以C答案对:如果setX和setY独立运行,check()可以返回TRUE。
答案已经得出,请楼主派分!谢谢拉!呵呵!

#26


#27


return x != y;我晕 看成return x == y;了

#28


免费申请二级域名
地址:http://www.nocoer.com        

注册的用户可以免费申请二级域名!               

申请后,只要在电子简历当中填写自己的个人资料!就可以通过访问二级域名来访问您的简历                

喜欢web开发的朋友多过来注册吧!               

让我们一起构造一个最庞大的人才库

#29



1 A
2 B
3 C E
4 B

胡乱添了一下,挺难的

#30


考把 x!=y错了
4: C