java练习册--类的继承

上传人:宝路 文档编号:20924257 上传时间:2017-11-22 格式:DOC 页数:2 大小:51.35KB
返回 下载 相关 举报
java练习册--类的继承_第1页
第1页 / 共2页
java练习册--类的继承_第2页
第2页 / 共2页
亲,该文档总共2页,全部预览完了,如果喜欢就下载吧!
资源描述

《java练习册--类的继承》由会员分享,可在线阅读,更多相关《java练习册--类的继承(2页珍藏版)》请在金锄头文库上搜索。

1、java 课程实践指导书文件编号:YM/WI-19文件版本: A 版文件页码:page of 练习册JAVA 篇类的多态和继承(3)一、练习目标:1 方法的重载和覆盖。2 类的多态,继承。二、练习时间与作业要求:本次练习一共需要 180 分钟。翻译练习写在 JAVA 笔记本上,书面作业写在 JAVA家庭作业本上。后面的书面作业不包括在这个时间范围内。三、翻译练习:将下面要求翻译的内容,写在记事本上(阴影部分不写出来,要求看懂)Order of constructor callsA constructor for the base class is always called during th

2、e construction process for a derived class, chaining up the inheritance hierarchy so that a constructor for every base class is called. This makes sense because the constructor has a special job: to see that the object is built properly. A derived class has access to its own members only, and not to

3、 those of the base class (whose members are typically private). Only the base-class constructor has the proper knowledge and access to initialize its own elements. Therefore, its essential that all constructors get called, otherwise the entire object wouldnt be constructed. Thats why the compiler en

4、forces a constructor call for every portion of a derived class. It will silently call the default constructor if you dont explicitly call a base-class constructor in the derived-class constructor body. If there is no default constructor, the compiler will complain. (In the case where a class has no

5、constructors, the compiler will automatically synthesize a default constructor.)The order of the constructor calls is important. When you inherit, you know all about the base class and can access any public and protected members of the base class. This means that you must be able to assume that all

6、the members of the base class are valid when youre in the derived class. In a normal method, construction has already taken place, so all the members of all parts of the object have been built. Inside the java 课程实践指导书文件编号:YM/WI-19文件版本: A 版文件页码:page of constructor, however, you must be able to assume

7、 that all members that you use have been built. The only way to guarantee this is for the base-class constructor to be called first. Then when youre in the derived-class constructor, all the members you can access in the base class have been initialized. Knowing that all members are valid inside the

8、 constructor is also the reason that, whenever possible, you should initialize all member objects (that is, objects placed in the class using composition) at their point of definition in the class (e.g., b, c, and l in the preceding example). If you follow this practice, you will help ensure that al

9、l base class members and member objects of the current object have been initialized.四、上机练习:1、 编写一个图形类。然后通过继承图形类,产生三角形,圆形,正方形。目的能计算出任意多个图形的面积之和。2、 编写三个系别的学生类:英语系,计算机系,文学系(要求通过继承学生类)各系有以下成绩:英语系: 演讲,期末考试,期中考试;计算机系:操作能力,英语写作,期中考试,期末考试;文学系: 演讲,作品,期末考试,期中考试;各系总分评测标准:英语系: 演讲 50%期末考试 25%期中考试 25%计算机系: 操作能力 40%英语写作 20%期末考试 20%期中考试 20%文学系: 演讲 35%作品 35%期末考试 15%期中考试 15%定义一个可容纳 5 个学生的学生类数组,使用随机数给该数组装入各系学生的对象,然后按如下格式输出数组中的信息:学号:XXXXXXXX 姓名:XXX 性别:X 年龄:XX 综合成绩:XX

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号