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

题目

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;)private ”相关问题
  • 第1题:

    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

  • 第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=2

    B.x1=12,x2=10

    C.x1=12,x2=2

    D.x1=2,x2=2


    正确答案:C
    解析:本题考核派生类的构造函数。在C++中,构造函数不能被继承,因此,派生类的构造函数必须通过调用基类的构造函数来初始化基类子对象。所以,在定义派生类的构造函数时,除了对自己的数据成员进行初始化外,还必须负责调用基类构造函数使基类的数据成员得以初始化。如果派生类中还有子对象,还应包含对子对象初始化的构造函数。

  • 第3题:

    include<iostream.h>

    class A

    {

    private:

    int x,y;

    public:

    void f1(int i=0,int j=0){x=i;y=j;}

    void print(){cout<<x<<" "<<y<<endl;}

    void f1(int i=0){x=i,y=0;}

    };

    void main()

    {

    A a;

    a.f1(5);

    a.print();

    }


    正确答案:
    a.f1(5);重载函数产生了二义性。应删去其中一个函数f1。

  • 第4题:

    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

  • 第5题:

    若有以下程序: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=2

    B.x1=12,x2=10

    C.x1=12,x2=2

    D.x1=2,x2=2


    正确答案:C
    解析:本题考核派生类的构造函数。在C++中,构造函数不能被继承,因此,派生类的构造函数必须通过调用基类的构造函数来初始化基类子对象。所以,在定义派生类的构造函数时,除了对自己的数据成员进行初始化外,还必须负责调用基类构造函数使基类的数据成员得以初始化。如果派生类中还有子对象,还应包含对于对象初始化的构造函数。