分析并给出下列程序的运行输出结果: class Shape { private static int i; protected static int j=10; Shape () { System.out.println ("i = " + i + ", j = " + j); j = 5; } private static int x1 = printInit("private Shape.x1 initialized"); static int printInit(String s) { System.out.println (s); return ++i; } } public class Circle extends Shape { int k = printInit("Circle.k initialized"); public Circle () { System.out.println ("k = " + k); System.out.println ("j = " + j); System.out.println ("x2 = " + x2); super.printInit("super"); } public static int x2 = printInit("public Circle.x2 initialized"); public static void main(String[] args) { System.out.println ("Circle constructor"); Circle b = new Circle (); System.out.println ("b.k="+b.k); } }
第2题
class Shape{
public:
virtual void Draw()=0;
};
下列关于 Shape 类的描述中,正确的是
A )类 Shape 是虚基类
B )类 Shape 是抽象类
C )类 Shape 中的 Draw 函数声明有误
D )语句 “ Shape s; ” 能够建立 Shape 的一个对象 s
第3题
A.类Shape是虚基类
B.类Shape是抽象类
C.类Shape中的Draw函数声明有误
D.语句“ShapeS;”能够建立Shape的一个对象S
第4题
A.类Shape是虚基类
B.类Shape是抽象类
C.类Shape中的Draw函数声明有误
D.语句“Shape s;”能够建立Shape的一个对象s
第5题
classShape{
public:
virtualvoidDraw( )=0;
}
下列关于Shape类的描述中,正确的是( )。
A.类Shape是虚基类
B.类Shape是抽象类
C.类Shape中的Draw函数声明有误
D.语句“ShapeS;”能够建立Shape的一个对象S
第6题
运行程序,则看到的结果是
A.交替显示正方形和圆形,每秒交替一次
B.交替显示矩形和椭圆形,每秒交替一次
C.显示正方形,每秒闪烁一次
D.显示椭圆形,每秒移动一次
第7题
A.一切成功编译
B.Shape可以编译,Square不能编译
C.Square可以编译,Shape不能编译
D.Square,Shape都不能编译
第8题
B.类Shape是抽象类
C.类Shape中的Draw函数声明有误
D.“Shape s;”能建立Shape的对象s
第9题
[说明]
以下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
第10题
运行程序后产生的结果是
A.圆逐渐缩小,再逐渐增大,然后再逐渐缩小,依此往复
B.圆一直在缩小
C.圆每隔0.5秒向右移动一次
D.圆每隔1秒向下移动一次
为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!