Shape s = new Shape(); s.setAnchor(10,10); s.draw();
Circle c = new Shape(); c.setAnchor(10,10); c.draw();
Shape s = new Circle(); s.setAnchor(10,10); s.draw();
Shape s = new Circle(); s->setAnchor(10,10); s->draw();
Circle c = new Circle(); c.Shape.setAnchor(10,10); c.Shape.draw();
第1题:
有如下类声明: class XA{ int X; public: XA(int n){x=n;} }; class XB:public XA{ int y; public: XB(int a,int b); }; 在构造函数XB的下列定义中,正确的是( )。
A.XB::XB(inta,int b):x(a),y(b){}
B.XB::XB(int a,int b):XA(a),y(b){}
C.XB::XB(int a,int b):x(a),XB(b){}
D.XB::XB(int a,int b):XA(a),XB(b){}
第2题:
阅读以下说明和C++代码,填入(n)处。
[说明]
以下C++代码使用虚函数实现了同一基类shape派生出来的Class rectangle、Class triangle、Class circle实现了计算矩形、圆形面积的计算。仔细阅读以下代码,将(n)处语句补充完整。
[代码5-1]
include<iostream.h>
define PI 3.14159
class shape {//基类
protected:
(1);
public:
(2);
(3);
};
[代码5-2]
class rectangle: public shape {
public:
rectangle (int x2,int y2,int r2): (4) {};
double area ( ) {return x*y; };
};
class circle: public shape {
public:
circle (int x3,int y3,int r3):(5){};
double area ( ) {return r*r*PI; };
};
[代码5-3]
void main ( )
{
rectangle r (10,20,0);
circle c (0,0,30);
shape (6);
cout<<"长方形面积="<<s1->area ( ) <<endl;
cout<<"圆形面积="<<s2->area ( ) <<endl;
}
[运行结果]
长方形面积=200
圆形面积=2827.43
第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.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.1
B.123
C.242
D.244
第5题:
在下列源代码文件Test.java中,正确定义类的代码是( )。
A.pblic 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.protected class Test extends T2{ public int x = 0; public Test(int x) { this. x = x; } }
第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题:
有如下类声明: class XA { int x; public: XA(int n){x=n;} }; class XB:public XA { int y; public: XB(int a,int b); }; 在构造函数XB的下列定义中,正确的是
A.XB::XB(int a,int b):x(a),y(b){}
B.XB::XB(int a,int b):XA(a),y(b){}
C.XB::XB(int a,int b):x(a),XB(b){}
D.XB::XB(int a,int b):XA(a),XB(b){}
第8题:
有如下程序: #include<iostream> using namespace std; class Base{ int x; public: Base(int n=0):x(n){cout<<n;} int getX( )const{return x;} }; class Derived:public Base{ int y; public: Derived(int m,int n):y(m),Base(n){tout<<m;} Derived(int m):y(m){cout<<m;} }; int main( ){ Derived dl(3),d2(5,7); return 0; } 程序的输出结果是
A.375
B.357
C.0375
D.0357
第9题:
有以下程序: #include<iostream> using namespace std; #definePl 3.14 Class Point {private: int x,y; public: Point(int a,intB) {X=a; y:b;} int getx() <return x;} int gety() {return y;}}; class Circle:public Point {pri
A.314
B.157
C.78.5
D.153.86
第10题:
有如下类声明: class XA { int x; public: XA(int n) {x=n;} }; class XB: public XA{ int y; public: XB(int a,int b); };在构造函数XB的下列定义中,正确的是______。
A.XB:: XB(int a, int b):x(a),y(b) { }
B.XB::XB(int a, int b):XA(a),y(b){}
C.XB::XB(int a,int b):x(a),XB(b)i}
D.XB::XB(int a,int b):XA(a),XB(b){}