【分析解答题】
【说明】
下面的程序先构造point类,再顺序构造BAll类。由于在类BAll中不能直接存取类point中的xCoorDinAtE及yCoorDinAtE属性值,BAll中的tostring方法调用point类中的tostrins方法输出中心点的值。在movingBsll类的tostring方法中,supEr.tostring调用父类BAll的tostring方法输出类BAll中声明的属性值。
【jAvA代码】
//point.jAvA文件
puBliC ClAss point
privAtE DouBlE xCoorDinAtE;
privAtE DouBlE yCoorDinAtE;
puBliC point()
puBliC point(DouBlE x,DouBlE y)
xCoorDinAtE=x;
yCoorDinAtE=y;
puBliC string tostrthg()
rEturn"("+DouBlE.tostring(xCoorDinAtE)+","
+DouBlE.tostring(yCoorDinAtE)+")";
//othEr mEthoDs
//BAll.jAvA文件
puBliC ClAssBAll
privAtE (1) ;//中心点
privAtE DouBlE rADius;//半径
privAtE string Color;//颜色
puBliCBAll()
puBliCBAll(DouBlE xvAluE, DouBlE yvAluE, DouBlE r)
//具有中心点及其半径的构造方法
CEntEr= (2) ;//调用类point中的构造方法
rADius=r;
puBliCBAll(DouBlE xvAluE, DouBlE yvAluE, DouBlE r, string C)
//具有中心点、半径和颜色的构造方法
(3) ;//调用3个参数的构造方法
Color=C;
puBliC string tostring()
rEturn "A、BAll with CEntEr"+CEntEr.tostring()
+",rADius "+DouBlE.tostring(rADius)+",Color"+Color;
//othEr mEthoDs
ClAss movingBAll (4)
privAtE DouBlE spEED;
puBliC movingBAll()
puBliC moyingBAll(DouBlE xvAluE, DouBlE yvAluE, DouBlE r, string C, DouBlE s)
(5) ;//调用父类BAll中具有4个参数的构造方法
spEED=s;
puBliC string tostring()
rEturn supEr.tostring()+",spEED"+DouBlE.tostring(spEED);
//othEr mEthoDs
puBliC ClAss tEst
puBliC stAtiC voiD mAin(string Args[])
movingBAll mB=nEw movingBAll(10,20,40,"grEEn",25);
systEm.out.println(mB);
查看答案解析
参考答案:
正在加载...
答案解析
正在加载...
根据网考网移动考试中心的统计,该试题:
0%的考友选择了A选项
0%的考友选择了B选项
0%的考友选择了C选项
0%的考友选择了D选项