其他

publicclassThreads1{intx=0;publicclassRunnerimplementsRunnable{publicvoidrun(){intcurrent=0;for(int=i=0;i<4;i++){current=x;System.out.print(current+,);x=current+2;}}}publicstaticvoidmain(String[]args){newThreads1().go();}publicvoidgo(){Runnabler1=newRunne

题目

publicclassThreads1{intx=0;publicclassRunnerimplementsRunnable{publicvoidrun(){intcurrent=0;for(int=i=0;i<4;i++){current=x;System.out.print(current+,);x=current+2;}}}publicstaticvoidmain(String[]args){newThreads1().go();}publicvoidgo(){Runnabler1=newRunner();newThread(r1).start();newThread(r1).start();}}Whichtwoarepossibleresults?()

A.0,2,4,4,6,8,10,6,

B.0,2,4,6,8,10,2,4,

C.0,2,4,6,8,10,12,14,

D.0,0,2,2,4,4,6,6,8,8,10,10,12,12,14,14,

E.0,2,4,6,8,10,12,14,0,2,4,6,8,10,12,14,

如果没有搜索结果,请直接 联系老师 获取答案。
如果没有搜索结果,请直接 联系老师 获取答案。
相似问题和答案

第1题:

要定义整型数组x,使之包括初值为0的三个元素,下列语句中错误的是()

A.int x[3]={0,0,0};

B.int x[ ]={0};

C.int x[3]={0};

D.int x[ ]={0,0,0};


D 解析:选项D中整型数组x的第一个元素是NULL不是0,故选D。

第2题:

要定义整型数组x,使之包括初值为0的三个元素,下列语句中错误的是()

A.int x[ ]={0,0,0};

B.int x[ ]={0};

C.int x[3]={0};

D.int x[3]={0,0,0};


D 解析:选项D中整型数组x的第一个元素是NULL不是0,故选D。

第3题:

1、要定义整型数组x,使之包括初值为0的三个元素,下列语句中错误的是()

A.int x[3]={0,0,0};

B.int x[ ]={0};

C.int x[3]={0};

D.int x[ ]={0,0,0};


D

第4题:

下列函数原型声明中错误的是

A.void Fun(int x=0,int y=0);

B.void Fun(int x,int y);

C.void Fun(int x,int y=0);

D.void Fun(int x=0,int y);


正确答案:D
解析:本题考核函数的定义方法和调用方法。说明一个函数的格式为:函数类型>函数名>(函数参数表>);。在C++中,允许在函数的说明或定义时给一个或多个参数指定默认值。但一旦为某个给定参数定义了缺省值,必须为后继的所有参数也定义缺省值。由此可知,选项D是错误的。

第5题:

下列函数原型声明中错误的是( )。

A.void Fun(int x=0,int y=0);

B.void Fun(int x,int y);

C.void Fun(int x,int y=0);

D.void Fun(int x=0,int y);


正确答案:D

第6题:

下列函数原型声明中错误的是( )。

A.void fuc(int x=0,int y=0)

B.void fnc(int x,int y)

C.void fuc(int x,int y=0)

D.void fuc(int x=0,int y)


正确答案:D
解析:C++允许在函数的说明或定义中给一个或多个参数指定默认值。但默认值必须从右向左定义,即在一个指定默认值的参数的右边,不能出现没有指定默认值的参数。

第7题:

publicclassTestFive{privateintx;publicvoidfoo(){intcurrent=x;x=current+1;}publicvoidgo(){for(inti=0;i<5;i++){newThread(){publicvoidrun(){foo();System.out.print(x+,);}}.start();}}}Whichtwochanges,takentogether,wouldguaranteetheoutput:1,2,3,4,5,?()

A.Movetheline12printstatementintothefoo()method.

B.Changeline7topublicsynchronizedvoidgo(){.

C.Changethevariabledeclarationonline3toprivatevolatileintx;.

D.Wrapthecodeinsidethefoo()methodwithasynchronized(this)block.

E.Wraptheforloopcodeinsidethego()methodwithasynchronizedblocksynchronized(this){//forloopcodehere}.


参考答案:A, D

第8题:

publicclassTestSevenextendsThread{privatestaticintx;publicsynchronizedvoiddoThings(){intcurrent=x;current++;x=current;}publicvoidrun(){doThings();}}Whichistrue?()

A.Compilationfails.

B.Anexceptionisthrownatruntime.

C.Synchronizingtherun()methodwouldmaketheclassthread-safe.

D.Thedatainvariable“x”areprotectedfromconcurrentaccessproblems.

E.DeclaringthedoThings()methodasstaticwouldmaketheclassthread-safe.

F.WrappingthestatementswithindoThings()inasynchronized(newObject()){}blockwouldmaketheclassthread-safe.


参考答案:E

第9题:

下列函数原型声明中错误的是

A.void Fun(int x=O,int y=0);

B.void Fun(int x,int y);

C.void Fun(int x,int y=0);

D.void Fun(int x=0,int y);


正确答案:D
解析:本题考核函数的定义方法和调用方法。说明一个函数的格式为:函数类型>函数名>,(下函数参数表>);在C++中,允许在函数的说明或定义时给一个或多个参数指定默认值。但一旦为某个给定参数定义了缺省值,必须为后继的所有参数也定义缺省值。由此可知,选项D是错误的。