


全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
文件编号:YM/WI-19文件版本: A版文件页码:page of java课程实践指导书JAVA篇 JAVA语言中的类的继承一、练习目标:掌握类的继承的一般方法。二、练习时间与作业要求:本次练习一共需要180分钟。翻译练习写在JAVA笔记本上,书面作业写在JAVA家庭作业本上。后面的书面作业不包括在这个时间范围内。三、翻译练习:将下面要求翻译的内容,写在记事本上Understanding Inheritance A subclass inherits variables and methods from its superclass and all of its ancestors. The subclass can use these members as is, or it can hide the member variables or override the methods. What Members Does a Subclass Inherit?Rule: A subclass inherits all of the members in its superclass that are accessible to that subclass unless the subclass explicitly hides a member variable or overrides a method. Note that constructors are not members and are not inherited by subclasses. The following list itemizes the members that are inherited by a subclass: Subclasses inherit those superclass members declared as public or protected. Subclasses inherit those superclass members declared with no access specifier as long as the subclass is in the same package as the superclass. Subclasses dont inherit a superclasss member if the subclass declares a member with the same name. In the case of member variables, the member variable in the subclass hides the one in the superclass. In the case of methods, the method in the subclass overrides the one in the superclass. Creating a subclass can be as simple as including the extends clause in your class declaration. However, you usually have to make other provisions in your code when subclassing a class, such as overriding methods or providing implementations for abstract methods. Hiding Member VariablesAs mentioned in the previous section, member variables defined in the subclass hide member variables that have the same name in the superclass. While this feature of the Java language is powerful and convenient, it can be a fruitful source of errors. When naming your member variables, be careful to hide only those member variables that you actually wish to hide. One interesting feature of Java member variables is that a class can access a hidden member variable through its superclass. Consider the following superclass and subclass pair: class Super Number aNumber;class Subbie extends Super Float aNumber;The aNumber variable in Subbie hides aNumber in Super. But you can access Supers aNumber from Subbie with super.aNumbersuper is a Java language keyword that allows a method to refer to hidden variables and overridden methods of the superclass. 四、上机练习:1、修改人类,增加一个静态的属性和和两个静态方法,并做如下测试:1)在静态方法中分别访问该类的静态与非静态属性2)在静态方法中分别访问该类的静态与非静态方法3)在非静态方法中分别访问该类的静态属性与方法4)在测试类的main方法直接去引用该类的属性与方法,看能使用哪些属性与方法?5)实例化一个该类,看还能不能通过该类的对象对访问它的静态方法6)实例化两个该类的对象,通过一个对象将类的静态属性改变,看一个另一个对象的该属性有没有改变。2、修改人类,在其中增加一个输出该人信息的方法printInfo(),修改学生类,包含学号属性格式为:前四位代表入学日期后四位是学生的编号,覆盖人类printInfo()方法,并提供一个自己的方法getInDate(String id)能通过
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025内蒙古鑫和资源投资集团有限责任公司招聘26名模拟试卷及答案详解(易错题)
- Histone-H3-1-21-Gly-Gly-Lys-biotinyl-amide-TFA-生命科学试剂-MCE
- Hedgehog-IN-11-生命科学试剂-MCE
- 2025内蒙古自治区农牧业科学院纳入总量管理控制数招聘模拟试卷附答案详解(黄金题型)
- Go-6983-Standard-生命科学试剂-MCE
- 紧急救援行业报告及市场前景
- 2025江西人力诚聘派驻江西江铜华东铜箔有限公司劳务派遣人员14人考前自测高频考点模拟试题及答案详解一套
- 2025广东揭阳市普宁市公安局招聘警务辅助人员80人考前自测高频考点模拟试题及答案详解(全优)
- 桩基钻芯取样专业合同7篇
- 公共服务品质保障承诺书3篇范文
- 光伏电站智能监控系统建设方案
- 2025年干细胞治疗行业研究报告及未来行业发展趋势预测
- 供水工程成本预算与动态控制方案
- (2025年标准)清理乱账服务协议书
- GB/T 45860.1-2025光纤激光束焊机的验收试验第1部分:光纤输送机的激光组件
- 卒中后抑郁症的中医治疗
- 2025年4月自考00155中级财务会计试题及答案含评分标准
- DB50∕T 1653-2024 林区森林防火及森林质量提升专项规划编制导则
- 道路工程培训课件
- 制冰厂可行性研究报告
- 国庆假期大学生安全教育
评论
0/150
提交评论