publicclassSyncTest{privateintx;privateinty;publicsynchronizedvoidsetX(inti)(x=1;)publicsynchronizedvoidsetY(inti)(y=1;)publicsynchronizedvoidsetXY(int1)(setX(i);setY(i);)publicsynchronizedBooleancheck()(returnx!=y;)}Underwhichconditionswillcheck()returnt

题目

publicclassSyncTest{privateintx;privateinty;publicsynchronizedvoidsetX(inti)(x=1;)publicsynchronizedvoidsetY(inti)(y=1;)publicsynchronizedvoidsetXY(int1)(setX(i);setY(i);)publicsynchronizedBooleancheck()(returnx!=y;)}Underwhichconditionswillcheck()returntruewhencalledfromadifferentclass?

A.Check()canneverreturntrue.

B.Check()canreturntruewhensetXYiscalledbymultiplethreads.

C.Check()canreturntruewhenmultiplethreadscallsetXandsetYseparately.

D.Check()canonlyreturntrueifSyncTestischangedtoallowxandytobesetseparately.


相似考题
更多“publicclassSyncTest{privateintx;privateinty;publicsynchronizedvoidsetX(inti)(x=1;)publicsy ”相关问题
  • 第1题:

    publicclassXimplementsRunnable(privateintx;privateinty;publicstaticvoidmain(String[]args)(Xthat=newX();(newThread(that)).start();(newThread(that)).start();)publicsynchronizedvoidrun()(for(;;)(x++;y++;System.out.printIn(x=+x+,y=+y);)))Whatistheresult?()

    A.Anerroratline11causescompilationtofail.

    B.Errorsatlines7and8causecompilationtofail.

    C.Theprogramprintspairsofvaluesforxandythatmightnotalwaysbethesameonthesameline(forexample,“x=2,y=1”)

    D.Theprogramprintspairsofvaluesforxandythatarealwaysthesameonthesameline(forexample,“x=1,y=1”.Inaddition,eachvalueappearstwice(forexample,“x=1,y=1”followedby“x=1,y=1”)

    E.Theprogramprintspairsofvaluesforxandythatarealwaysthesameonthesameline(forexample,“x=1,y=1”.Inaddition,eachvalueappearstwice(forexample,“x=1,y=1”followedby“x=2s,y=2”)


    参考答案:E

  • 第2题:

    publicclassXimplementsRunnable{privateintx;privateinty;publicstaticvoidmain(String[]args){Xthat=newX();(newThread(that)).start();(newThread(that)).start();}publicvoidrun(){for(;;){synchronized(this){x++;y++;}System.out.println(Thread.currentThread().getName()+x=+x+,y=+y);}}}Whatistheresult?()

    A.Compilationfails.

    B.Theprogramprintspairsofvaluesforxandythatmightnotalwaysbethesameonthesameline(forexample,“x=2,y=1”).

    C.Theprogramprintspairsofvaluesforxandythatarealwaysthesameonthesameline(forexample,“x=1,y=1”). Inaddition,eachvalueappearsonlyonce(forexample,“x=1,y=1”followedby“x=2,y=2”). Thethreadnameatthestartofthelineshowsthatboththreadsareexecutingconcurrently.

    D.Theprogramprintspairsofvaluesforxandythatarealwaysthesameonthesameline(forexample,“x=1,y=1”). Inaddition,eachvalueappearsonlyonce(forexample,“x=1,y=1”followedby“x=2,y=2”). Thethreadnameatthestartofthelineshowsthatonlyasinglethreadisactuallyexecuting.


    参考答案:D

  • 第3题:

    publicclassXimplementsRunnable(privateintx;privateinty;publicstaticvoidmain(Stringargs)(Xthat=newX();(newThread(that)).start();(newThread(that)).start();)publicsynchronizedvoidrun()(for(;;)(x++;y++;System.out.printIn(x=+x+,y=+y);)))Whatistheresult?()

    A.Anerroratline11causescompilationtofail.

    B.Errorsatlines7and8causecompilationtofail.

    C.Theprogramprintspairsofvaluesforxandythatmightnotalwaysbethesameonthesameline(forexample,“x=2,y=1”)

    D.Theprogramprintspairsofvaluesforxandythatarealwaysthesameonthesameline(forexample,“x=1,y=1”.Inaddition,eachvalueappearstwice(forexample,“x=1,y=1”followedby“x=1,y=1”)

    E.Theprogramprintspairsofvaluesforxandythatarealwaysthesameonthesameline(forexample,“x=1,y=1”.Inaddition,eachvalueappearstwice(forexample,“x=1,y=1”followedby“x=2s,y=2”)


    参考答案:E

  • 第4题:

    publicclassSyncTest(privateintx;privateinty;privatesynchronizedvoidsetX(inti)(x=1;)privatesynchronizedvoidsetY(inti)(y=1;)publicvoidsetXY(int1)(setX(i);setY(i);)publicsynchronizedBooleancheck()(returnx!=y;))Underwhichconditionswillcheck()returntruewhencalledfromadifferentclass?

    A.Check()canneverreturntrue.

    B.Check()canreturntruewhensetXYiscalledbymultiplethreads.

    C.Check()canreturntruewhenmultiplethreadscallsetXandsetYseparately.

    D.Check()canonlyreturntrueifSyncTestischangedtoallowxandytobesetseparately.


    参考答案:B

  • 第5题:

    publicclassSyncTest{privateintx;privateinty;privatesynchronizedvoidsetX(inti){x=i;}privatesynchronizedvoidsetY(inti){y=i;}publicvoidsetXY(inti){setX(i);setY(i);}publicsynchronizedbooleancheck(){returnx!=y;}}Underwhichconditionwillcheckreturntruewhencalledfromadifferentclass?()

    A.checkcanneverreturntrue.

    B.checkcanreturntruewhensetXYiscalledbymultiplethreads.

    C.checkcanreturntruewhenmultiplethreadscallsetXandsetYseparately.

    D.checkcanreturntrueonlyifSyncTestischangedtoallowxandytobesetseparately.


    参考答案:B