Giventhefollowingcode,whichstatementsconcerningtheobjectsreferencedthroughthemembervariablesi,jandkaretrue,giventhatanythreadmaycallthemethodsa,bandcatanytime?()classCounter{intv=0;synchronizedvoidinc(){v++;}synchronizedvoiddec(){v--;}}publicclassQ7ed5{Counteri;Counterj;Counterk;publicsynchronizedvoida(){i.inc();System.out.println(a);i.dec();}publicsynchronizedvoidb(){i.inc();j.inc();k.inc();System.out.println(b);i.dec();j.dec();k.dec();}publicvoidc(){k.inc();System.out.println(c);k.dec();}}
Giventhefollowingcode,whichstatementsconcerningtheobjectsreferencedthroughthemembervariablesi,jandkaretrue,giventhatanythreadmaycallthemethodsa,bandcatanytime?()
classCounter{intv=0;
synchronizedvoidinc(){v++;}
synchronizedvoiddec(){v--;}
}
publicclassQ7ed5{
Counteri;
Counterj;
Counterk;
publicsynchronizedvoida(){
i.inc();
System.out.println("a");
i.dec();}
publicsynchronizedvoidb(){
i.inc();
j.inc();
k.inc();
System.out.println("b");
i.dec();
j.dec();
k.dec();}
publicvoidc(){
k.inc();
System.out.println("c");
k.dec();
}
}
相关考题:
Giventhefollowingcode:1)classParent{2)privateStringname;3)publicParent(){}4)}5)publicclassChildextendsParent{6)privateStringdepartment;7)publicChild(){}8)publicStringgetValue(){returnname;}9)publicstaticvoidmain(Stringarg[]){10)Parentp=newParent();11)}12)}Whichlinewillcauseerror?()A.line3B.line6C.line7D.line8E.line10
Giventhefollowingcode:publicclassPerson{intarr[]=newint[10];publicstaticvoidmain(Stringa[]){System.out.println(arr[1]);}}Whichstatementiscorrect?() A.Whencompilationsomeerrorwilloccur.B.Itiscorrectwhencompilationbutwillcauseerrorwhenrunning.C.Theoutputiszero.D.Theoutputisnull.
Giventhefollowingcode:publicclassPerson{staticintarr[]=newint[10];publicstaticvoidmain(Stringa[]){System.out.println(arr[1];)}}Whichstatementiscorrect?() A.Whencompilationsomeerrorwilloccur.B.Itiscorrectwhencompilationbutwillcauseerrorwhenrunning.C.Theoutputiszero.D.Theoutputisnull.
Giventhefollowingcode:1)publicvoidmodify(){2)inti,j,k;3)i=100;4)while(i0){5)j=i*2;6)System.out.println(Thevalueofjis+j);7)k=k+1;8)i--;9)}10)}Whichlinemightcauseanerrorduringcompilation?()A.line4B.line6C.line7D.line8
Giventhefollowingcode:publicclassTest{voidprintValue(intm){do{System.out.println(Thevalueis+m);}while(--m10)}publicstaticvoidmain(Stringarg[]){inti=10;Testt=newTest();t.printValue(i);}}Whichwillbeoutput?()A.Thevalueis8B.Thevalueis9C.Thevalueis10D.Thevalueis11
Giventhefollowingcode:if(x0){System.out.println(first);}elseif(x-3){System.out.println(second);}else{System.out.println(third);}Whichrangeofxvaluewouldprintthestringsecond?()A.x0B.x-3C.x=-3D.x=0x-3
Giventhefollowingcode,whichmethoddeclarations,wheninsertedattheindicatedposition,willnotcausetheprogramtofailcompilation?()publicclassQdd1f{publiclongsum(longa,longb){returna+b;}//insertnewmethoddeclarationhere}A.publicintsum(inta,intb){returna+b;}B.publicintsum(longa,longb){return0;}C.abstractintsum();D.privatelongsum(longa,longb){returna+b;}E.publiclongsum(longa,intb){returna+b;}
Giventhefollowingcode,writealineofcodebase);}}classExtentionextendsBase{publicvoidprint(){System.out.println(extension);//insertlineofimplementationhere}}publicclassQ294d{publicstaticvoidmain(Stringargs[]){Extentionext=newExtention();ext.print();}}Fillinasinglelineofimplementation.()
Giventhefollowingcode,whichcodefragments,wheninsertedattheindicatedlocation,willsucceedinmakingtheprogramdisplayabuttonspanningthewholewindowarea?()importjava.awt.*;publicclassQ1e65{publicstaticvoidmain(Stringargs[]){Windowwin=newFrame();Buttonbut=newButton(button);//insertcodefragmentherewin.setSize(200,200);win.setVisible(true);}}A.win.setLayout(newBorderLayout());win.add(but);B.win.setLayout(newGridLayout(1,1));win.add(but);C.win.setLayout(newBorderLayout());win.add(but,BorderLayout.CENTER);D.win.add(but);E.win.setLayout(newFlowLayout());win.add(but);