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

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

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.


参考答案

更多 “ 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. ” 相关考题
考题 publicabstractclassShape{privateintx;privateinty;publicabstractvoiddraw();publicvoidsetAnchor(intx,inty){this.x=x;this.y=y;}}WhichtwoclassesusetheShapeclasscorrectly?() A.publicclassCircleimplementsShape{privateintradius;}B.publicabstractclassCircleextendsShape{privateintradius;}C.publicclassCircleextendsShape{privateintradius;publicvoiddraw();}D.publicabstractclassCircleimplementsShape{privateintradius;publicvoiddraw();}E.publicclassCircleextendsShape{privateintradius;publicvoiddraw(){/*codehere*/}}F.publicabstractclassCircleimplementsShape{privateintradius;publicvoiddraw(){/codehere*/}}

考题 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.

考题 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”)

考题 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.

考题 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.

考题 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”)

考题 若有以下程序:includeusing namespaces std;class A{public: A(){} A(int i) {xl=i; 若有以下程序: #include<iostream> using namespaces std; class A { public: A(){} A(int i) { xl=i; } void dispa() { cout<<"x1="<<x1<<","; } private: int x1; }; class B:public A { public: B(){} B(int i):A(i+10) { x2=i; } void dispb() { dispa(); cout<<"x2="<<x2<<endl; } private: int x2; }; int main{) { B b(2); b.dispb(): return 0; } 程序运行后的输出结果是A.x1=10,x2=2B.x1=12,x2=10C.x1=12,x2=2D.x1=2,x2=2

考题 若有以下程序:includeusing namespaces std;class A{public:A(){}A(int i){x1=i; } v 若有以下程序: #include<iOStream> using namespaces std; class A { public: A(){} A(int i) { x1=i; } void dispa() { cout<<"X1="<<x1<<",": } private; int x1; }; class B:public A { public: B(){} B(int i):A(i+10) { x2=i; } void dispb() { dispa(); cout<<"x2="<<x2<<end1; } private: int x2; }; . int main() { B b(2); b.dispb() return 0; } 程序运行后的输出结果是( )。A.x1=10,x2=2B.x1=12,x2=10C.x1=12,x2=2D.x1=2,x2=2

考题 includeiostream.hclass A{private:int x,y;public:void f1(int i=0,int j=0){x=i;y=j;}void print(){coutx yendl;}void f1(int i=0){x=i,y=0;}};void main(){A a;a.f1(5);a.print();}