类的继承
来源:互联网 发布:知乎学堂错题本 编辑:程序博客网 时间:2024/06/06 02:38
package test5;public class people {protected double weight,height;public void speakHello(){System.out.println("yayayaya");}public void averageHeight(){height = 173;System.out.println("average height:"+height);}public void averageWeight(){weight = 70;System.out.println("average weight:"+weight);}}
package test5;public class China extends people{public void speakHello(){System.out.println("你好!");}public void averageHeight(){height = 168.78;System.out.println("中国人的平均身高:"+height+"厘米");}public void averageWeight(){weight = 65;System.out.println("中国人的平均体重:"+weight+"KG");}public void chinaGongfu(){System.out.println("坐如钟,站如松,睡如弓");}}
package test5;public class American extends people{public void speakHello(){System.out.println("How do you do?");}public void averageHeight(){height = 176;System.out.println("American's average height:" + height + "cm.");}public void averageWeight(){weight = 75;System.out.println("American's average weight:" + weight + "kg.");}public void americanBoxing(){System.out.println("直拳、勾拳、组合拳。");}}
package test5;public class BeiJing extends China {public void averageHeight(){height = 172.5;System.out.println("北京人的平均身高:" + height + "cm.");}public void averageWeight(){weight = 172.5;System.out.println("北京人的平均体重:" + weight + "kg.");}public void beijingOpera(){System.out.println("花脸、青衣、花旦、老生");}}
package test5;public class Example {public static void main(String[] args) {China china = new China();American ame = new American();BeiJing bj = new BeiJing();china.speakHello();ame.speakHello();bj.speakHello();china.averageHeight();china.averageWeight();ame.averageHeight();ame.averageWeight();bj.averageHeight();bj.averageWeight();china.chinaGongfu();ame.americanBoxing();bj.chinaGongfu();bj.beijingOpera();}}
阅读全文
0 0
- c++类的继承:私有继承,公有继承,保护继承
- 类的继承 保护继承和私有继承
- C#类的继承-什么是继承
- 继承QVector----模板类的继承
- 类的一般继承与虚继承
- 继承:单继承、派生类成员的访问属性、多继承、菱形继承、虚继承,菱形虚拟继承
- java 类的继承
- 类的继承
- C#类的继承
- JavaScript类的继承
- C++ 类的继承
- 类的继承
- Java类的继承
- 类的继承
- 抽象类的继承
- 类的继承
- 类的继承用法
- 类的继承方式
- 共饮同井水
- 一个程序猿的理财和反思
- 温度转换(顺序结构)
- 学习springMVC遇到的配置问题!!
- 桥接模式(Bridge Pattern)——处理多维度变化
- 类的继承
- what day is today(分支结构)
- 求和(循环结构)
- baseRTC: 提取编译webRTC的base库
- Construct2:自制简易超级玛丽射击游戏进阶
- SpringBoot--整合Mybatis和Redis
- TensorFlow利用saver保存和提取参数
- 小程序合集
- proxy_pass_request_headers off的坑