网友您好, 请在下方输入框内输入要搜索的题目:

题目内容 (请给出正确答案)

publicclassSyncTest{

publicstaticvoidmain(Stringargs){

finalStringBuffers1=newStringBuffer();

finalStringBuffers2=newStringBuffer();

newThread(){

publicvoidrun(){

synchronized(s1){

s2.append(A”);

synchronized(s2){

s2.append(B”);

System.out.print(s1);

System.out.print(s2);

}

}

}

}.start();

newThread(){

publicvoidrun(){

synchronized(s2){

s2.append(C”);

synchronized(s1){

s1.append(D”);

System.out.print(s2);

System.out.print(s1);

}

}

}

}.start();

}

}

Whichtwostatementsaretrue?()


参考答案

更多 “ publicclassSyncTest{publicstaticvoidmain(Stringargs){finalStringBuffers1=newStringBuffer();finalStringBuffers2=newStringBuffer();newThread(){publicvoidrun(){synchronized(s1){s2.append(A”);synchronized(s2){s2.append(B”);System.out.print(s1);System.out.print(s2);}}}}.start();newThread(){publicvoidrun(){synchronized(s2){s2.append(C”);synchronized(s1){s1.append(D”);System.out.print(s2);System.out.print(s1);}}}}.start();}}Whichtwostatementsaretrue?() ” 相关考题
考题 interfaceDeclareStuff{publicstaticfinalintEASY=3;voiddoStuff(intt);}publicclassTestDeclareimplementsDeclareStuff{publicstaticvoidmain(String[]args){intx=5;newTestDeclare().doStuff(++x);}voiddoStuff(ints){s+=EASY+++s;System.out.println(”s+s);}}Whatistheresult?()A.s14B.s16C.s10D.Compilationfails.E.Anexceptionisthrownatruntime.

考题 publicclassX{publicstaticvoidmain(String[]args){strings=newstring(Hello”);modify(s);System.out.printIn(s);}publicstaticvoidmodify(Strings){s+=world!”;}}Whatistheresult?() A.Theprogramrunsandprints“Hello”B.Anerrorcausescompilationtofail.C.Theprogramrunsandprints“Helloworld!”D.Theprogramrunsbutabortswithanexception.

考题 publicclassfoo{staticStrings;publicstaticvoidmain(String[]args){system.out.printIn(s=”+s);}}Whatistheresult?() A.Thecodecompilesand“s=”isprinted.B.Thecodecompilesand“s=null”isprinted.C.Thecodedoesnotcompilebecausestringsisnotinitialized.D.Thecodedoesnotcompilebecausestringscannotbereferenced.E.Thecodecompiles,butaNullPointerExceptionisthrownwhentoStringiscalled.

考题 publicclassfoo{publicstaticvoidmain(String[]args){Strings;system.out.printIn(s=”+s);}}Whatistheresult?() A.Thecodecompilesand“s=”isprinted.B.Thecodecompilesand“s=null”isprinted.C.Thecodedoesnotcompilebecausestringsisnotinitialized.D.Thecodedoesnotcompilebecausestringscannotbereferenced.E.Thecodecompiles,butaNullPointerExceptionisthrownwhentoStringiscalled.

考题 publicclassX{publicstaticvoidmain(Stringargs){strings=newstring(Hello”);modify(s);System.out.printIn(s);}publicstaticvoidmodify(Strings){s+=world!”;}}Whatistheresult?() A.Theprogramrunsandprints“Hello”B.Anerrorcausescompilationtofail.C.Theprogramrunsandprints“Helloworld!”D.Theprogramrunsbutabortswithanexception.

考题 publicclassfoo{publicstaticvoidmain(Stringargs){Strings;system.out.printIn(s=”+s);}}Whatistheresult?() A.Thecodecompilesand“s=”isprinted.B.Thecodecompilesand“s=null”isprinted.C.Thecodedoesnotcompilebecausestringsisnotinitialized.D.Thecodedoesnotcompilebecausestringscannotbereferenced.E.Thecodecompiles,butaNullPointerExceptionisthrownwhentoStringiscalled.

考题 下列程序的输出结果是( )。 public class Test { public static void main (String[] args) { String s="hello"; s.replace ('r','m'); System.out.println(s); } }A.helloB.HELLOC.hemmoD.HEMMO

考题 1、写出以下程序的运行结果? public class Test{ public static void main(String argv[]){ String s = new String("hello"); myMethod(s); System.out.print("s=" + s); } public static void myMethod(String s){ s = s + "!"; } }A.s=hello!B.s=helloC.hello!D.hello

考题 写出以下程序的运行结果? public class Test{ public static void main(String argv[]){ String s = new String("hello"); myMethod(s); System.out.print("s=" + s); } public static void myMethod(String s){ s = s + "!"; } }A.s=hello!B.s=helloC.hello!D.hello