若类A和类B的定义如下:class A{int i,j;public:void get();//…};class B:A//默认为私有派生{int

题目

若类A和类B的定义如下: class A { int i,j; public: void get(); //… } ; class B:A//默认为私有派生 { int k; public: void make(); //… }; void B::make() { k=i*j; } 则上述定义中, ( )是非法的表达式。

A.void get();

B.int k;

C.void make();

D.k=i*j;

如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

若类A和类B的定义如下,则上述定义中, 是非法的表达式。 class A { int i,j; public: void get(); //… }; class B : A //默认为私有派生 { int k; public: void make(); //… }; void B :: make() { k=i*j;}

A.void get();

B.int k;

C.void make();

D.k=i*j;


k=i*j;

第2题:

37、若类A和类B的定义如下: class A { int i,j; public: void get(); file://… }; class B:A//默认为私有派生 { int k; public; void make(); file://… }; void B:: make() { k=i*j;} 则上述定义中,()是非法的表达式。

A.void get();

B.int k;

C.void make();

D.k=i*j;


A

第3题:

阅读下列说明和C++代码,填写程序中的空(1)~(6),将解答写入答题纸的对应栏内。
【说明】
以下C++代码实现一个简单绘图工具,绘制不同形状以及不同颜色的图形。部分类及其关系如图6-1所示。



【C++代码】
#include?#include?using?namespace?std;class?DrawCircle?{??????//绘制圆形,抽象类? ? ? public: (1);//定义参数为?int?radius,?int?x,?inty? ?virtual~DrawCircle()?{?}};class?RedCircle:public?DrawCircle?{????//绘制红色圆形? ? ? ? public: void?drawCircle(intradius,?int?x,?int?y)?{cout?<?drawCircle?=?drawCircle;? }? ?virtual~shape()?{?}? public:? ?virtual?void?draw()?=?0;};class?Circle:public?Shape?{????//圆形? ? private:? ? ?int?x,y,radius;? ? public:? Circle(int?x,inty,int?radius,DrawCircle?*drawCircle)? (3)? {? this->x?=?x;? ?this->y?=?y;? ? this->radius?=?radius; }? ? ? public:? void?draw(){? drawCircle?-> (4); }};int?main(){Shape?*redCirclenew?Circle(100,100,10,????(5)????);//绘制红色圆形? Shape?*greenCircle=new?Circle(100,100,10, (6)??);//绘制绿色圆形redCircle >draw();? ?greenCircle?->draw();? ?return?0;}


答案:
解析:
(6)(1)void drawCircle (int radius,int x,int y)
(2)DrawCircle*drawCircle
(3)drawcircle
(4)drawCircle(radius,x,y)
(5)new RedCircle()
(6)new GreenCircle()【解析】
第一空是填接口里面的方法,在接口的实现里面找,可以发现应该填void drawCircle (int radius,int x,int y)。
第二空可以根据后面this drawCircle=drawCircle判断,这里应该有一个drawCircle属性,因此应该填)DrawCircle drawCircle。
第三空这里填drawcircle,用-> drawcircle来引用父类的成员。
第四空调用drawCircle(radius,x,y)方法。
第五、六空分别创建一个红色圆形对象和一个绿色圆形对象作为Circle里面的实参。

第4题:

阅读以下说明和Java程序,填写程序中的空(1)~(6),将解答写入答题纸的对应栏内。
【说明】
以下Java代码实现一个简单绘图工具,绘制不同形状以及不同颜色的图形。部分接口、类及其关系如图5-1所示。




【Java代码】
interface?DrawCircle?{? //绘制圆形 public(1) ;}class?RedCircle?implements?DrawCircle?{? ?//绘制红色圆形???????public?void?drawCircle(int?radius,intx,?int?y)??{????????????System.out.println("Drawing?Circle[red,radius:"?+?radius?+",x:"?+?x?+?",y:"?+y+?"]");???????}}class?GreenCircle?implements?DrawCircle?{????//绘制绿色圆形??????public?void?drawCircle(int?radius,?int?x,int?y)?{???????????System.out.println("Drawing?Circle[green,radius:"?+radius+",x:?"?+x+?",y:?"?+y+?"]");??????}}abstract?class?Shape?{????//形状? protected? ? (2)???;? ? public?Shape(DrawCircle?drawCircle)?{? ?this.drawCircle=?drawCircle;? ? ? public?abstract?void?draw();}class?Circle?extends?Shape?{? //圆形? ?private?int?x,y,radius;? public?Circle(int?x,int?y,intradius,DrawCircle?drawCircle)?{? ?(3)???;? this.x?=?x;? ? ? this.y?=?y;? ?this.radius?=radius;? }? ? ?public?void?draw()?{? ? drawCircle.? ?(4)? ?;? ? ? }}public?class?DrawCircleMain?{? public?static?void?main(String[]?args)?{? Shape?redCircle=new?Circle(?100,100,10,? (5) );//绘制红色圆形? Shape?greenCircle=new?Circle(200,200,10,(6) );//绘制绿色圆形? ?redCircle.draw(); greenCircle.draw();? ?}}


答案:
解析:
(1)void drawCircle (int radius,int x,int y)
(2)DrawCircle drawCircle
(3)super.drawcircle=drawcircle
(4)drawCircle(radius,x,y)
(5)new RedCircle()
(6)new GreenCircle()【解析】
第一空是填接口里面的方法,在接口的实现里面找,可以发现应该填void drawCircle (int radius,int x,int y)。
第二空可以根据后面this drawCircle=drawCircle判断,这里应该有一个drawCircle属性,因此应该填)DrawCircle drawCircle。
第三空这里用super,用super. drawcircle来引用父类的成员。
第四空调用drawCircle(radius,x,y)方法。
第五、六空分别创建一个红色圆形对象和一个绿色圆形对象作为Circle里面的实参。

第5题:

若类A和类B的定义如下: class A { int i, public: void get(); / /... }; class B:A//默认为私有派生 { int k; public: void make(); / /... }; void B: :make() { k=i*j; } 则上述定义中, ( )是非法的表达式。

A.void get();

B.int k:

C.void make();

D.k=i*j;


正确答案:D

第6题:

对于下面( )类定义,可以通过“newJ_Class()”生成类J_Class的实例对象。

A、publicclassJ_Class{

publicJ_Class(void){}

}

B、publicclassJ_Class{}

C、publicclassJ_Class{

publicJ_Class(Strings){}

}

D、publicclassJ_Class{

publicvoidJ_Class(){}

publicJ_Class(Strings){}


正确答案:B

第7题:

用于定义类成员的访问控制权限的一组关键字是

A.extends 和 implements

B.public,private 和 protected

C.class和public

D.char,int,float和double


正确答案:B
解析:修饰符分为访问限制符和非访问限制符。其中访问限制符有pub-lic.orivate.protected和default。非访问限制符有static,final和abstract等。

第8题:

若类A和类B的定义如下:includeclass A{int i*j;public:int geti(){return i;}};class

若类A和类B的定义如下: #include<malloc.h> class A { int i*j; public: int geti() { return i; } }; class B: public A { int k; public: void make() { k=i*j; } ); 则上述定义中非法的表达式是( )。

A.k=i*j;

B.int k;

C.return i;

D.void make();


正确答案:A
解析:因为派生类不能访问基类的私有成员i和j(默认情况下,成员的属性为私有),所以表达式k=i*j是非法的。其余的访问权限都是许可的。

第9题:

若类A和类B的定义如下:includeclass A{int i,j;public:int geti(){return i;}};class

若类A和类B的定义如下: #include<malloc.h> class A { int i,j; public: int geti() { return i; } }; class B:public A { int k; public: void make() { k=i*j; } }; 则上述定义中非法的表达式是( )。

A.k=i*j

B.int k;

C.return i;

D.void make();


正确答案:A
解析:因为派生类不能是基类的私有成员i和j(默认情况下,成员的属性为私有),所以表达式k=i*j是非法的。其余的访问权限都是许可的。