300-100-100-100-100
300-300-100-100-100
300-300-300-100-100
300-300-300-300-100
第1题:
有如下程序: #include <iostream> using namespace std; class Part{ public: Part(int x=0):val(x) { cout<<val; } ~Part() { cout<<val; } private: int val; }; class Whole { public: Whole(int x, int y, int z=0):p2(x),p1 (y),val(z) { cout<<val; } ~whole() { cout<<val; private: Part p1,p2; int val; }; int main() { Whole obj (1,2,3); return 0; }程序的输出结果是
A.123321
B.213312
C.213
D.123123
第2题:
classFoo{
privateintx;
publicFoo(intx){this.x=x;}
publicvoidsetX(intx){this.x=x;}
publicintgetX(){returnx;}
}
publicclassGamma{
staticFoofooBar(Foofoo){
foo=newFoo(100);
returnfoo;
}
publicstaticvoidmain(String[]args){
Foofoo=newFoo(300);
System.out.print(foo.getX()+-);
FoofooFoo=fooBar(foo);
System.out.print(foo.getX()+-);
System.out.print(fooFoo.getX()+-);
foo=fooBar(fooFoo);
System.out.print(foo.getX()+-);
System.out.prmt(fooFoo.getX());
}
}
Whatistheoutputofthisprogram?()
第3题:
有如下类定义:
class Foo
{
public:
Foo(int v):value(v){} // ①
~Foo(){} // ②
private:
Foo(){} // ③
int value = 0; // ④
};
其中存在语法错误的行是
A . ①
B . ②
C . ③
D . ④
第4题:
有以下程序: #include <iostream> using namespace std; #define PI 3.14 class Point { private: int x,y; public: Point(int a,int b) { x=a; y=b; } int getx() { return x; } int gety() { return y; } }; class Circle : public Point { private: int r; public: Circle(int a,int b,int c):Point(a,b) { r=c; } int getr() { return r; } double area() { return PI*r*r; } }; int main() { Circle c1(5,7,10); cout<<cl.area()<<endl; return 0; } 程序执行后的输出结果是
A.314
B.157
C.78.5
D.153.86
第5题:
有如下程序: #include<iostream> using namespace std; class Part{ public: Part(int x=0):val(x) {cout<<val;} ~Part(){cout<<val;} private: int val; }; class Whole{ public: Whole(int x ,int y, int z=0):p2(x),p1(y),val(z){cout<<val;} ~Whole(){cout<<val;} private: Part p1,p2; int val; }; int main() Whole obj(1,2,3); return 0; } 程序的输出结果是( )。
A.123321
B.213312
C.213
D.123123
第6题:
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
第7题:
10.publicclassFooimplementsjava.io.Serializable{11.privateintx;12.publicintgetX(){returnx;}12.publicFoo(intx){this.x=x;}13.privatevoidwriteObject(ObjectOutputStreams)14.throwsIOException{15.//insertcodehere16.}17.}Whichcodefragment,insertedatline15,willallowFooobjectstobecorrectlyserializedanddeserialized?()
A.s.writeInt(x);
B.s.serialize(x);
C.s.writeObject(x);
D.s.defaultWriteObject();
第8题:
( 29 )有如下程序:
#include<iostream>
using namespace std;
class Part{
public:
Part(int x=0):val(x) {cout<<val;}
~Part(){cout<<val;}
private:
int val;
};
class Whole{
public:
Whole(int x ,int y, int z=0):p2(x),p1(y),val(z){cout<<val;}
~Whole(){cout<<val;}
private:
Part p1,p2;
int val;
};
int main(){
Whole obj(1,2,3);
return 0;
}
程序的输出结果是
A ) 123321
B ) 213312
C ) 213
D ) 123123
第9题:
有如下类的定义。横线处的语句是( )。 class MyClass { public: MyClass(int a=0,int b=0) { X=a; Y=b; } void Change()const { X-=10; Y+=10; } private: ______intX, Y;
A.static
B.const
C.mutable
D.不需要填入内容
第10题:
有以下程序:
include<iostream.h>
class A
{
int x;
public:
A(int a)
{
x=a;
}
friend class B;
}
class B{
public:
void print(A a){
a. x--;
cout<<a.x<<end1;
}
};
void main()
{
A a(10);
B b;
b.print(a) ;
}
程序执行后的输出结果是【 】。