首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
阅读以下函数说明和Java代码,将应填入(n)处的字句写在对应栏内。 【说明】 下面的程序先构造Point类,再顺序构造Ball类。由于在类Ball中不能直接存取类Point中的xCoordinate及yCoordinate属性值,Ball中的
阅读以下函数说明和Java代码,将应填入(n)处的字句写在对应栏内。 【说明】 下面的程序先构造Point类,再顺序构造Ball类。由于在类Ball中不能直接存取类Point中的xCoordinate及yCoordinate属性值,Ball中的
admin
2009-02-15
38
问题
阅读以下函数说明和Java代码,将应填入(n)处的字句写在对应栏内。
【说明】
下面的程序先构造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 class Ball{
private (1);//中心点
private double radius;//半径
private String color;//颜色
public Ball(){}
public Ball(double xValue, double yValue, double r){
//具有中心点及其半径的构造方法
center=(2);//调用类Point中的构造方法
radius=r;
}
public Ball(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);
}
}
选项
答案
(1) Point center (2) new Point(xValue,yValue) (3) this(xValue,yValue,r) (4) extends Ball (5) super(xValue,yValue,r,c)
解析
在类Ball的有参数构造函数中,对成员变量center通过调用Point类的构造方法初始化,而center在类Ball中尚未声明。结合注释可得空(1)是将center变量声明为Point对象引用,故空(1)应填Point。空(2)是调用Point类的构造函数,根据题意,此处应将xValue和yValue作为参数调用类Point的有参数构造函数,故空(2)应填new Point(xValue,yValue)。
根据注释,空(3)是调用类Ball的有3个参数的构造方法,而其所在方法本身就是类Ball的一个构造方法,因此可用this来调用自身的构造方法,故空(3)应填this(xValue,yValue,r)。
根据题述“在MovingBall类的toString方法中,super.toString调用父类Ball的toString方法输出类Ball中声明的属性值”,可知类MovingBall是类Ball的子类,因此空(4)应填extends Ball。
根据注释,空(5)是调用父类Ball中具有4个参数的构造方法,通过super关键字实现,故空(5)应填super(xValue,yValue,r,c)。
转载请注明原文地址:https://jikaoti.com/ti/7wi7FFFM
本试题收录于:
软件设计师下午应用技术考试题库软考中级分类
0
软件设计师下午应用技术考试
软考中级
相关试题推荐
使用质量是从用户的角度来看待的产品质量,其属性不包括()。
在软件开发过程中,详细设计的内容不包括()设计。
对于防病毒系统的测试是系统安全测试的重要内容,下列不属于防病毒系统安全测试基本测试点的是____________。
以下关于用例图的叙述中,不正确的是(44)。图书馆管理系统需求中包含“还书”用例和“到书通知”用例,对于“还书”用例,应先查询该书是否有人预定,若有则执行“到书通知”。“还书”用例和“到书通知”用例是(45)关系,以下用例图中,(46)是正确的。管理员处
在结构化分析方法中,利用分层数据流图对系统功能建模。以下关于分层数据流图的叙述中,不正确的是___________(32)。采用数据字典为数据流图中的每个数据流、文件、加工以及组成数据流或文件的数据项进行说明,其条目不包括____________(33)。
如果在查找路由表时发现有多个选项匹配,那么应该根据___________(25)原则进行选择。假设路由表有4个表项如下所示,那么与地址139.17.179.92匹配的表项是____________(26)。(25)
零件关系P(零件名,条形码,供应商,产地,价格)中的(12)属性可以作为该关系的主键。查询产于西安且名称为“P2”的零件,结果以零件名、供应商及零件价格分列表示,对应的SQL语句为:SELECT零件名,供应商,价格FROMPWHE
某财务系统在使用过程中,因个人所得税政策变化,需修改计算工资的程序。这种修改属于______维护。
某文件管理系统采用位示图(bitmap)记录磁盘的使用情况。如果系统的字长为32位,磁盘物理块的大小为4MB,物理块依次编号为:0、1、2、…,位示图字依次编号为:0、1、2、…,那么16385号物理块的使用情况在位示图中的第(24)个字中描述;如果磁盘的
阅读以下说明,回答问题1至问题4,将解答填人答题纸的对应栏内。[说明]某小公司的网络拓扑如图9-2所示。其中路由器具有ISDN模块,公司网络通过ISDN连接到ISP。
随机试题
《吉檀迦利》的思想内容。
皮肤黏膜下出血点,直径在3~5mm之间称为()
A.相互独立的统计指标的大小B.事物中各部分比重的大小C.事物在时间上的发展变化D.事物的数量在地域上的分布E.两事物间的相关关系散点图表示的是
最应该考虑本病的流行病学特征描述错误的是
一天晚上某村召开村干部会议,因还未通电,就用煤油灯照明开会。会议中间灯没油了,村干部张某便找来新买来的煤油往灯里加油,当煤油刚倒出接近明火时,突然爆发,将身边的另一乡干部王某炸死。经化验鉴定,当天新买的煤油里,被油脂公司掺进了汽油。下列选项对张某的行为在主
如图所示,两端铰支的矩形截面木杆承受压力作用。已知杆长为l=1.5m,横截面尺寸为b=10mm,h=24mm,材料弹性模量E=10GPa,则该压杆的临界压力Fcr为()。
福海公司是国内一家著名的肉类加工企业,为了保持业绩持续增长,福海公司近年来陆续收购了几家规模较大的养殖场、肉类连锁超市,福海公司采取的发展战略属于()。(2016年)
黄金:铂金:金属
属于《宪法》中既是义务又是权利的是()
扩展名为pjx的文件是( )。
最新回复
(
0
)