java 第八周 继承 接口
来源:互联网 发布:淘宝文胸买家秀图片 编辑:程序博客网 时间:2024/06/06 14:50
/* (程序头部注释开始)* 程序的版权和版本声明部分* Copyright (c) 2011, 烟台大学计算机学院学生 * All rights reserved.* 文件名称: * 作 者: 姜雅明 * 完成日期: 2012 年 10 月 18 日* 版 本 号: 2.0 * 对任务及求解方法的描述部分* 输入描述: * 问题描述: * 程序输出: * 程序头部的注释结束*/
/*封装一个People类型,具有height和weight属性, *具有speakHello、averageHeight、averageWeight功能。 */public class People {protected int height;protected int weight;People(){height = 180;weight = 65;}public void speakHello(){System.out.println("Hello");}public void averageHeight(){System.out.println("the averageHeight is:" + height);}public void averageWeight(){System.out.println("the averageWeight is:" + weight);}}
/*封装一类ChinaPeople类型是People的子类,新增chinaMartial功能, * override超类的speakHello、averageHeight、averageWeight功能。 */public class ChinaPeople extends People{ChinaPeople(){super();this.height = 175;this.weight = 55;}public void chinaMartial(){System.out.println("中国爱好和平。");}public void speakHello(){System.out.println("你好");}public void averageHeight(){//System.out.println(super.height);System.out.println("中国人的平均身高是:" + height);}public void averageWeight(){System.out.println("中国人的平均体重是:" + weight);}}
/*封装一类AmericanPeople类型是People的子类, * 新增AmericanBoxing功能, * override超类的speakHello、averageHeight、averageWeight功能。 */public class AmericanPeople extends People{AmericanPeople(){super();}public void AmericanBoxing(){System.out.println("This is America Boxing!!!");}public void speakHello(){System.out.println("Hello,I'm from America.");}public void averageHeight(){System.out.println("The averageheight of America is :" + height);}public void averageWeight(){System.out.println("The averageweight of America is :" + weight);}}
/*封装一类BeijingPeople类型是ChinaPeople的子类, * 新增BeijingOpera功能, * override超类的speakHello、averageHeight、averageWeight功能。 */public class BeijingPeople extends ChinaPeople{BeijingPeople(){super();}public void BeijngOpera(){System.out.println("国粹京剧");}public void speakHello(){System.out.println("你好,我是北京人。");}public void averageHeight(){System.out.println("北京人的平均身高是:" + height);}public void averageWeight(){System.out.println("北京人的平均体重是:" + weight);}}
public class Test {/** * @param args */public static void main(String[] args) {// TODO Auto-generated method stubPeople p = new People();ChinaPeople c = new ChinaPeople();p.averageHeight();p.averageWeight();c.averageHeight();c.averageWeight();}}
接口练习:
package two;/*封装一类接口ComputerWeight,该接口中有3个功能:double computrWeight,void printName,double printPrice。 */public interface ComputerWeight {double computerWeight();void printName();double printPrice(double price);}
package two;/*封装一类接口ComputerCompany,该接口有2个功能:String computerName,void printFunction。 */public interface ComputerCompany {String computerName(String name);void printFunction();}
package two;/*封装一类对象FlashMemory实现上述两类接口。 */public class FlashMemory implements ComputerCompany, ComputerWeight{private String name;private double price;public double computerWeight(){double weight = 30;return weight;}public void printName(){System.out.println("The name of the computer is : " + name);}@Overridepublic String computerName(String name) {this.name = name;return this.name;}@Overridepublic void printFunction() {System.out.println("This computer can do everything!!!");}@Overridepublic double printPrice(double price) {this.price = price;return this.price;}}
package two;public class Test {/** * @param args */public static void main(String[] args) {// TODO Auto-generated method stubFlashMemory f = new FlashMemory();String str = "lenovo";f.computerName(str);f.printName();System.out.println("The weight of the computer is : " + f.computerWeight());f.printFunction();System.out.println("The price of the computer is :" + f.printPrice(7998));}}
好像是计算机组成原理老师说过不喜欢加注释,然后我也发现我不喜欢加注释·····要改,要改·······虽然这次还是没加注释······
- java 第八周 继承 接口
- JAVA--第八周实验--继承的练习
- 第八周JAVA实验之继承
- JAVA--第八周实验--接口的练习
- 第八周JAVA实验之接口
- Java接口继承接口
- java第八章(1)继承
- Java从入门到精通学习笔记---第八章 接口、继承与多态
- java上机 第八周 任务1 继承的练习
- java * 第八周* 任务【一】继承的练习
- java第八章(3)接口
- java接口 接口实现 继承
- java 接口继承接口作用
- java继承与接口
- Java 接口和继承
- java接口的继承
- java--继承,抽象,接口
- java 接口多继承
- 你应该知道的vim插件之surround.vim
- Qt简介以及如何配置Qt使用VS2010进行开发
- 进程间的通信方式
- org.hibernate.TransactionException: JDBC rollback failed错误解决方法
- 软件工程总结
- java 第八周 继承 接口
- 一个linux下修改文件权限的实例
- C03-Java同步实践加强班第9周上机任务
- 回忆太美 也太伤人:伤感日志
- 一致性hash
- Android Gallery用法(自定义边框+底部小圆点)
- c 韩信点兵
- IOS发布问题
- 【全网首发】云计算的关键技术与应用实例_王鹏_高清PDF扫描版下载