While institutions often follow development trends, academic disputes are more timeless.
A.YES
B.NO
C.NOT GIVEN
第1题
A.0
B.null
C.Compilationfails.
D.ANullPointerExceptionisthrownatruntime.
E.AnArrayIndexOutOfBoundsExceptionisthrownatruntime.
第2题
A.privatesynchronizedObjecto;
B.voidgo(){synchronized(){/*codehere*/}}
C.publicsynchronizedvoidgo(){/*codehere*/}
D.privatesynchronized(this)voidgo(){/*codehere*/}
E.voidgo(){synchronized(Object.class){/*codehere*/}}
F.voidgo(){Objecto=newObject();synchronized(o){/*codehere*/}}
第3题
A.Movetheline12printstatementintothefoo()method.
B.Changeline7topublicsynchronizedvoidgo(){.
C.Changethevariabledeclarationonline3toprivatevolatileintx;.
D.Wrapthecodeinsidethefoo()methodwithasynchronized(this)block.
E.Wraptheforloopcodeinsidethego()methodwithasynchronizedblocksynchronized(this){//forloopcodehere}.
第4题
publicclassNameList{
privateListnames=newArrayList();
publicsynchronizedvoidadd(Stringname){names.add(name);}
publicsynchronizedvoidprintAll(){
for(inti=0;iSystem.out.print(names.get(i)+);
}
}
publicstaticvoidmain(String[]args){
finalNameListsl=newNameList();
for(inti=0;i<2;i++){
newThread(){
publicvoidruin(){
sl.add(”A”);
sl.add(”B”);
sl.add(”C”);
sl.printAll();
}
}.start();
}
}
}
Whichtwostatementsaretrueifthisclassiscompiledandrun?()
第5题
A.0,2,4,4,6,8,10,6,
B.0,2,4,6,8,10,2,4,
C.0,2,4,6,8,10,12,14,
D.0,0,2,2,4,4,6,6,8,8,10,10,12,12,14,14,
E.0,2,4,6,8,10,12,14,0,2,4,6,8,10,12,14,
第6题
A.declarereset()usingthesynchronizedkeyword
B.declaregetName()usingthesynchronizedkeyword
C.declaregetCount()usingthesynchronizedkeyword
D.declaretheconstructorusingthesynchronizedkeyword
E.declareincrement()usingthesynchronizedkeyword
第7题
privatestaticObjectresource=newObject();
privatestaticvoiddelay(longn){
try{Thread.sleep(n);}
catch(Exceptione){System.out.print(”Error);}
}
publicstaticvoidmain(String[]args){
System.out.print(”StartMain);
newThread1().start();
delay(1000);
Threadt2=newThread2();
t2.start();
delay(1000);
t2.interrupt
delay(1000);
System.out.print(”EndMain);
}
staticclassThread1extendsThread{
publicvoidrun(){
synchronized(resource){
System.out.print(”Startl);
delay(6000);
System.out.print(”End1);
}
}
}
staticclassThread2extendsThread{
publicvoidrun(){
synchronized(resource){
System.out.print(”Start2);
delay(2000);
System.out.print(”End2);
}
}
}
}
Assumethatsleep(n)executesinexactlymmilliseconds,andallothercodeexecutesinaninsignificantamountoftime.Whatistheoutputifthemain()methodisrun?()
第8题
A.Compilationfails.
B.Anexceptionisthrownatruntime.
C.Thecodeexecutesandprints“StartedComplete”.
D.Thecodeexecutesandprints“StartedComplete0123”.
E.Thecodeexecutesandprints“Started0l23Complete”.
第9题
A.Compilationfails.
B.Anexceptionisthrownatruntime.
C.Thecodeexecutesnormallyandprints“sleep”.
D.Thecodeexecutesnormally,butnothingisprinted.
第10题
A.java.lang.RuntimeException:Problem
B.run. java.lang.RuntimeException:Problem
C.Endofmethod. java.lang.RuntimeException:Problem
D.Endofmethod. run.java.lang.RuntimeException:Problem
E.run. java.lang.RuntimeException:ProblemEndofmethod.
为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!