Giventhefollowingcode,whichstatementsconcerningtheobjectsreferencedthroughthemembervariablesi,jandkaretrue,giventhatanythreadmaycallthemethodsa,bandcatanytime?()classCounter{intv=0;synchronizedvoidinc(){v++;}synchronizedvoiddec(){v--;}}publicclassQ7ed5{Co

题目

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,whichstatementsconcerningt ”相关问题
  • 第1题:

    Giventhefollowingcode:publicclassTest{voidprintValue(intm){do{System.out.println("Thevalueis"+m);}while(--m>10)}publicstaticvoidmain(Stringarg[]){inti=10;Testt=newTest();t.printValue(i);}}Whichwillbeoutput?()

    A.Thevalueis8

    B.Thevalueis9

    C.Thevalueis10

    D.Thevalueis11


    参考答案:C
    此题考察的是do…while循环和--操作符的知识,do…while最少被执行一次,在执行完do中的内容后判断while中的条件是否为true,如果为true的话就再执行do中的内容,然后再进行判断,以此类推直到while的判断为false时退出循环执行循环后面的内容,而—操作符的规则是在变量右边的--将先进行运算,然后才是使变量的值减一,而在变量左边的是先将变量的值减一再运算。

  • 第2题:

    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;}


    参考答案:A, E

  • 第3题:

    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);


    参考答案:A, B, C, D

  • 第4题:

    Giventhefollowingcode:if(x>0){System.out.println("first");}elseif(x>-3){System.out.println("second");}else{System.out.println("third");}Whichrangeofxvaluewouldprintthestring"second"?()

    A.x>0

    B.x>-3

    C.x<=-3

    D.x<=0&x>-3


    参考答案:D

    x>0时打印"first",x>-3&&x<=0时打印"second",x<=-3时打印"third"。这个题目没有什么难的,只要理解if语句的语法就可以了。

  • 第5题:

    Giventhefollowingcode,writealineofcode&ens

    Giventhefollowingcode,writealineofcodethat,wheninsertedattheindicatedlocation,willmaketheoverridingmethodinExtensioninvoketheoverriddenmethodinclassBaseonthecurrentobject.

    classBase{

    publicvoidprint(){

    System.out.println("base");

    }

    }

    classExtentionextendsBase{

    publicvoidprint(){

    System.out.println("extension");

    //insertlineofimplementationhere

    }

    }

    publicclassQ294d{

    publicstaticvoidmain(Stringargs[]){

    Extentionext=newExtention();

    ext.print();

    }

    }

    Fillinasinglelineofimplementation.()


    参考答案:super.print();