找考题网-背景图
单项选择题

publicclassTwoThreads{privatestaticObjectresource=newOb……

publicclassTwoThreads{
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?()

A.sleep(n);}
B.out.print(”Error);}
C.out.print(”StartMain);
D.start();
E.start();
F.interrupt
G.out.print(”EndMain);
H.out.print(”Startl);
I.out.print(”End1);
J.out.print(”Start2);
K.out.print(”End2);
热门试题