public class X implements Runnable ( private int x; private int y; public static void main(String args) ( X that = new X(); (new Thread(that)) . start( ); (new Thread(that)) . start( ); ) public synchronized void run( ) ( for (;;) ( x++; y++; System.out.printIn(“x = “ + x + “, y = “ + y); ) ) ) What is the result?()
第1题:
以下程序输出结果为______。
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;
}
第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: d; };
A.1
B.2
C.3
D.4
第3题:
下列程序的输出结果是非曲直【 】。
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;
}
第4题:
有如下程序; #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,2
B.12,2
C.12,10
D.10,2
第5题:
为完成下面的程序,应在划线处填入的语句是 #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);}
第6题:
下列程序的功能是为变量赋值,程序运行后,输出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);
}
}
第7题:
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
第8题:
( 31 )有如下程序:
#include
using namespace std;
class A
{
public;
A ( int i ) {x= i ;}
Void sispa () {cout<<X<< ’ , ’ ;}
Private:
int x ;
};
class B;publicA
{
public;
B ( int i ) :A ( i +10 ) {x =i ;}
voud dispb () {dispa () ;cout<<X<,ENDL;}
Private:
Int x;
};
int main ()
{
B b ( 2 ) ;
b.dispb ()
retum 0:
}
运行时输出的结果是
A ) 10 , 2
B ) 12 , 10
C ) 12 , 2
D ) 2 , 2
第9题:
有以下程序
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;
}
运行后的打印结果是______。
第10题:
下面程序的打印结果是【 】。
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;
}