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

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

1.publicclassXimplementsRunnable(2.privateintx;3.privateinty;4.5.publicstaticvoidmain(String[]args)6.Xthat=newX();7.(newThread(that)).start();8.(newThread(that)).start();9.)10.11.publicvoidrun()(12.for(;;)(13.x++;14.y++;15.System.out.printIn(x=”+x+,y=”+y);16.)17.)Whatistheresult?()

A.Errorsatlines7and8causecompilationtofail.

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

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

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


参考答案

更多 “ 1.publicclassXimplementsRunnable(2.privateintx;3.privateinty;4.5.publicstaticvoidmain(String[]args)6.Xthat=newX();7.(newThread(that)).start();8.(newThread(that)).start();9.)10.11.publicvoidrun()(12.for(;;)(13.x++;14.y++;15.System.out.printIn(x=”+x+,y=”+y);16.)17.)Whatistheresult?()A.Errorsatlines7and8causecompilationtofail.B.Theprogramprintspairsofvaluesforxandythatmightnotalwaysbethesameonthesameline(forexample,“x=2,y=1”).C.Theprogramprintspairsofvaluesforxandythatarealwaysthesameonthesameline(forexample,“x=1,y=1”.Inaddition,eachvalueappearstwice(forexample,“x=1,y=1”followedby“x=1,y=1”).D.Theprogramprintspairsofvaluesforxandythatarealwaysthesameonthesameline(forexample,“x=1,y=1”.Inaddition,eachvalueappearsonlyforonce(forexample,“x=1,y=1”followedby“x=2,y=2”). ” 相关考题
考题 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.

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

考题 阅读以下说明和Java代码,填充程序中的空缺,将解答填入答题纸的对应栏内。【说明】某应急交通控制系统(TraficControIS,stem)在红灯时控制各类车辆(Vehicle)的通行,其类图如图6-1所示,在紧急状态下应急车辆在红灯时可通行,其余车辆按正常规则通行。下面的Java代码实现以上设计,请完善其中的空缺。【Java代码】abstract class Vehiclepublic Vehicle () { }abstract void run};interface Emergency {(1) ;(2) ;}class Car extends Vehicle {public Car () { }void run () { /*代码略*/ }};class Truck extends Vehicle {public Truck () { }void run () { /*代码略*/ }class PoliceCar (3)boolean isEmergency = false;public PoliceCar () { }public PoliceCar(boolean b) { this . isEmergency =b; }public boolean isEmergent () { return (4); }public void runRedLight () { /*代码略*/ }}/*类Ambulance. FireEngine实现代码略*/public class TraficControISystem {/。交通控制类。/private Vehicle[ ]V=new Vehiele [24];int numVehicles;public void control() {for (int i=0; inumVehicles; i++) {if (v[i] instanceof Enu rgency ((Emergency)V [i])isEmergent()) {( 5 ) . runRedLigh: ( ) ;}else(6).run( )}}void add (Vehicle vehicle) { v[numVehicles++]=vehicle;)/*添加车辆*/void shutDown()(/*代码略*/}public static void main (Stri.ng [ ] args) {TraficControlSystem tcs = new TraficControlSystem() ;tcs . add (new Car () ;tcs .add (new PoliceCar () ;tcs .add (new Ambulance () ;tcs . add (new Ambulance (true》 ;tcs . add (new FireEngine ( true》 ;tcs . add (new Truck () ;tcs . add (new FireEngine ( ) ;tcs . control () ;tcs . shutDown () ;}}

考题 下列()方法可用于创建一个可运行的类。A.public class X implements Runnable{public void run() {……}}B.public class X implements Thread{public void run() {……}}C.public class X implements Thread{public int run() {……}}D.public class X implements Runnable{protected void run() {……}}