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

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

public class X implements Runnable(    private int x;   private int y;   public static void main(Stringargs)  X that = new X();   (new Thread(that)).start();  (new Thread(that)).start();  )  public void run() (  for (;;) (  x++;   y++;   System.out.printIn(“x=” + x + “, y = ” + y);   )   )   What is the result?()  

  • A、 Errors at lines 7 and 8 cause compilation to fail.
  • B、 The program prints pairs of values for x and y that might not always be the same on the same line  (for example, “x=2, y=1”).
  • C、 The program prints pairs of values for x and y that are always the same on the same line (for example, “x=1, y=1”. In addition, each value appears twice (for example, “x=1, y=1” followed by  “x=1, y=1”).
  • D、 The program prints pairs of values for x and y that are always the same on the same line (for example, “x=1, y=1”. In addition, each value appears only for once (for example, “x=1, y=1”  followed by “x=2, y=2”).

参考答案

更多 “ public class X implements Runnable(    private int x;   private int y;   public static void main(Stringargs)  X that = new X();   (new Thread(that)).start();  (new Thread(that)).start();  )  public void run() (  for (;;) (  x++;   y++;   System.out.printIn(“x=” + x + “, y = ” + y);   )   )   What is the result?()  A、 Errors at lines 7 and 8 cause compilation to fail.B、 The program prints pairs of values for x and y that might not always be the same on the same line  (for example, “x=2, y=1”).C、 The program prints pairs of values for x and y that are always the same on the same line (for example, “x=1, y=1”. In addition, each value appears twice (for example, “x=1, y=1” followed by  “x=1, y=1”).D、 The program prints pairs of values for x and y that are always the same on the same line (for example, “x=1, y=1”. In addition, each value appears only for once (for example, “x=1, y=1”  followed by “x=2, y=2”).” 相关考题
考题 下列程序的输出结果是非曲直【 】。includeclass base{ int x, y;public: base(int i, 下列程序的输出结果是非曲直【 】。include<iostream, h>class base{int x, y;public:base(int i, int j){x=i; y=j;}virtual int add(){return x+ y;}};class three: public base{int z;public:three(int i, int j, int k) :base(i, j){z=k; }int add() { return (base:: add()+z); }};void main(){three * q=new three(lO,20,30);cout<<q->add()<<end1;}

考题 ( 31 )有如下程序:#includeusing namespace std;class A{public;A ( int i ) {x= i ;}Void sispa () {coutX ’ , ’ ;}Private:int x ;};class B;publicA{public;B ( int i ) :A ( i +10 ) {x =i ;}voud dispb () {dispa () ;coutX,ENDL;}Private:Int x;};int main (){B b ( 2 ) ;b.dispb ()retum 0:}运行时输出的结果是A ) 10 , 2B ) 12 , 10C ) 12 , 2D ) 2 , 2

考题 以下程序输出结果为______。 include using namespace std; class TestClass 1 { publi 以下程序输出结果为______。include<iostream>using namespace std;class TestClass 1{public:TestClass1(){}TestClass1(int i){x1=i;}void dispa(){cout<<"x1="<<x1<<",";}private:int x1;}:class TestClass2:public TestClass1{public:TestClass2(){}TestClass2(int i):TestClass1(i+10){x2=i:}void dispb(){dispa();cout<<"x2="<<x2<<end1;}private:int x2:}:int main(){TestClass2 b(2):b.dispb();return 0;}

考题 下列程序的功能是为变量赋值,程序运行后,输出i=51。请改动main方法中的错误,使程序能够正确编译、运行并输出正确的结果。注意:不改动程序结构。class A{private int a;public void setA (int x){a=x;}public int getA(){return a;}}public class MethodTest{public static void main(String args[]){A a=A();a.getA(51);int i=a.getA();System.out.println ("i="+i);}}

考题 下列类的定义中,有( ) 处语法错误。 class Base { public: Base(){} Base(int i) { data=i; } private: int data; }; class Derive: public Base { public: Derive(): Base(O) { } Derive(int x) { d=x; } void setvalue(int i) { data=i; } private: d; };A.1B.2C.3D.4

考题 在如下源代码文件Test.java中, 哪个是正确的类定义?() A.public class test { public int x = 0; public test(int x) { this.x = x; } }B.public class Test{ public int x=0; public Test(int x) { this.x = x; } }C.public class Test extends T1, T2 { public int x = 0; public Test (int x) { this.x = x; } }D.public class

考题 为完成下面的程序,应在划线处填入的语句是includeusingnamespace std;class Base{pri 为完成下面的程序,应在划线处填入的语句是 #include<iostream> using namespace std; class Base { private: int x; public: Base (int i) { x=i; } ~Base(){} }; class Derived:public Base { public: ______________//完成类Derive构造函数的定义 }; int main() { Derived Obj; return 0; }A.Derived(int i):Base(i){}B.Derived(){}C.void Derived (int i):Base(i){}D.Derived(int i){Base(i);}

考题 有以下程序 include using namespace std; class Base { int a; public: Base(int x) 有以下程序include <iostream>using namespace std;class Base{int a;public:Base(int x){ a=x; }void show(){ cout<<a; }class Derived : public Base{int b;public:Derived(int i) :Base(i+1),b(i){}void show() { cout<<b;};int main (){Base b(5),*pb;Derived d(1);pb=d;pb->show ();return 0;}运行后的打印结果是______。

考题 有如下程序;include using namespace std;class Base{public;Base(inti){x=i;}void d 有如下程序; #include <iostream> using namespace std; class Base { public; Base(inti){x=i;} void dispa0{cout<<x<<',';} private; int x; }; class Derived;public Base { public; Derived(int i);Base(i+10) {x=i;) void dispb(){dispa();cout<<x<<end1;} private; int x; }; int main() { Derived b(2) ; b.dispb(); return 0; } 运行的结果是( )。A.2,2B.12,2C.12,10D.10,2

考题 下面程序的打印结果是【】。 include using namespace std; class Base { public:Base(i 下面程序的打印结果是【 】。include <iostream>using namespace std;class Base{public:Base(int x){a=x;}void show(){cout<<a;}private:int a;};class Derived : public Base{public:Derived(int i) :Base(i+1) ,b(i) { }void show(){cout<<b;}private:int b;};int main ( ){Base b(5) , *pb;Derived d(1);pb=d;pb->show();return 0;}

考题 下列程序输出结果为: include using namespace std; class TestClass1 { public: Test 下列程序输出结果为:include<iostream>using namespace std;class TestClass1{public:TestClass1(){}TestClass1(int i){x1=i;}void dispa(){cout<<"x1="<<x1<<",";}private:int x1;};class TestClass2:public TestClass1{public:TestClass2(){}TestClass2(int i):TestClass1(i+10){x2=i;}void dispb(){dispa();cout<<"x2="<<x2<<endl;}private:int x2;};int main(){TestClass2 b(2);b.dispb();return 0;}

考题 执行下面的程序段后,x的值为( )。 public class Sun { public static void main(String args[ ]) { int x=5; for(int i=l;i<=20;i=i+2) x=x+i/5; System.out.println(x); } }A.21B.22C.23D.24

考题 下面程序运行的结果是()。includeusing namespace std;class A{ protected:int a; pub 下面程序运行的结果是( )。 #include<iostream> using namespace std; class A{ protected: int a; public: void input(int i) {a=i;} }; class B{ protected: int a; public: void input(int j) {a=j;} }; class C: public A, public B { int x; public: void input() {x=A::a * B::a;cout<<x<<endl;} }; void main() { C c; c.A::input(5); c.B::input(8); c.input(); }A.5B.8C.40D.编译出错

考题 有如下程序: include class x { protected: int a; public:x(){ a=1;} }; class x 有如下程序: #include <iostream.h> class x { protected: int a; public: x() { a=1; } }; class x1 : virtual public x { public: x1() { a+=1; cout<<a; } }; class x2 : virtual public x { public: x2() { a+=2; cout<<a; } }; class y : public xl,public x2 { public: y() { cout<<a<<end1; } }; int main() { y obj; return O; } 该程序运行后的输出结果是( )。A.1B.123C.242D.244

考题 分析以下程序的执行结果【】。include class S{ int A[10]; public: int operato 分析以下程序的执行结果【 】。include <iostream. h>class S{int A[10];public:int operator () (int);};int S: :operator() (int x) {return A[x];}void main() {S a;int i,j;for (i=0; i<10; i++)a(i)=i*2;for (i=0; i<10; i++)cout<<a(i)<<" ";cout<<end1; }

考题 若有以下程序:include using namespaces std;class A{public: A (){} A (int i) {x1= 若有以下程序: #include <iostream> using namespaces std; class A { public: A (){} A (int i) { x1=i; } void dispa() { cout<<"xl="<<xl<<" , "; } 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

考题 有如下程序:includeusing namespace std;Class TestClass{int a;public:TestClass(in 有如下程序: #include<iostream> using namespace std; Class TestClass {int a; public: TestClass(int x){a=x;} void show(){cout<<a;}}; class TestClass1:public TestClass {int b; public: TestClass1(int i):TestClass(i+1),b(i){} voiA.5B.1C.0D.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

考题 下列类的定义中,有( )处语法错误。 class Base { public: Base(){} Base(int i) { data=i; } private: int data; }; class Derive : public Base { public: Derive() : Base(O) {} Derive (int x) { d=x; } void setvalue(int i) { data=i; } private: int d; };A.1B.2C.3D.4

考题 有如下程序: #inCludeiostream using namespaCe std; ClaSS A{ publiC: A(int i){x=i;} void dispa( ){Coutx’,’;} private: int x; }; Class B:publiC A{ publiC: B(int i):A(i+10){x=i;} vold dispb( ){dispa( );Coutxendl;} private: int x; }; int main( )} B b(2); b.dispb( ); return 0; } 执行这个程序的输出结果是( )。A.10,2B.12,10C.12,2D.2,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

考题 有以下程序: #include 〈iostream〉 using namespace std; class A { public: virtual void setx(int i,int j=0) { x=i; y=j; } virtual void print()=0; protected: int x,y; }; class B : public A { public: void print() { cout〈〈x*x〈〈", "; } }; class C : public A { public: void print() { cout〈〈x*x*x〈〈end1; } }; int main() { A *pa; B b; C c; pa=b; pa-setx(5); pa-print (); pa=c; pa-setx(2); pa-print(); return 0; } 程序运行后的输出结果是( )。A.25,8B.2,5C.5,2D.8,25

考题 下列程序的输出结果是______。 include class base { int x,y; public: base(int i,i 下列程序的输出结果是______。include<iostream.h>class base{int x,y;public:base(int i,int j){x=i;y=j;}virtual int add( ){return x+y;}};class three:public base{int z;public:three(int i,int j,int k):base(i,j){z=k;)int add( ){return(base::add( )+z);}};void main( ){three*q=new three(10,20,30);cout<<q->add( )<<endl;}

考题 在下面横线上填上适当的语句,完成程序。include using namespace std; class Base { in 在下面横线上填上适当的语句,完成程序。include<iostream>using namespace std;class Base{int x;public:Base(int i){x=i;}~Base(){});class Derived:public Base{public:______//完成类Derive构造函数的定义};iht main(){Derived obj

考题 Which are syntactically valid statement at// point x?()     class Person {     private int a;  public int change(int m){  return m;  }     }  public class Teacher extends Person {     public int b;  public static void main(String arg[]){     Person p = new Person();     Teacher t = new Teacher();    int i;  // point x     }    } A、 i = m;B、 i = b;C、 i = p.a;D、 i = p.change(30);E、 i = t.b.

考题 Which three demonstrate an “is a” relationship?() A、 public class X { }  public class Y extends X { }B、 public interface Shape { }  public interface Rectangle extends Shape{ }C、 public interface Color { }  public class Shape { private Color color; }D、 public interface Species { }  public class Animal { private Species species; }E、 public class Person { } public class Employee {  public Employee(Person person) { }F、 interface Component { }  class Container implements Component { private Component[] children; }

考题 现有:  public  class  TestDemo{     private int X-2;      static int y=3;  public  void method(){      final int i=100;      int j  =10;     class Cinner {  public void mymethod(){      //Here     }     }     }     } 在Here处可以访问的变量是哪些?() A、XB、yC、jD、i

考题 单选题public class SyncTest {  private int x;   private int y;   public synchronized void setX (int i) (x=1;)   public synchronized void setY (int i) (y=1;)   public synchronized void setXY(int 1)(set X(i); setY(i);)   public synchronized Boolean check() (return x !=y;)   }   Under which conditions will check () return true when called from a different class?A  Check() can never return true.B  Check() can return true when setXY is called by multiple threads.C  Check() can return true when multiple threads call setX and setY separately.D  Check() can only return true if SyncTest is changed to allow x and y to be set separately.