作业-继承2
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了作业-继承2相关的知识,希望对你有一定的参考价值。
创建如下三个类:(People类中的三个方法分别输出一些信息,ChinaPeople
和AmericanPeople类重写父类的三个方法)。
package T092202; public class People { protected double height; protected double weight; public double getHeight() { return height; } public void setHeight(double height) { this.height = height; } public double getWeight() { return weight; } public void setWeight(double weight) { this.weight = weight; } public void speakHello() { System.out.println("你好!!!"); } public void averageHeight() { System.out.println("平均身高是:"+height); } public void averageWeight() { System.out.println("平均体重是:"+weight); } } package T092202; public class ChinaPeople extends People { public void speakHello() { System.out.println("你好,我是中国人!"); } public void averageHeight() { System.out.println("中国人的平均身高是:"+height); } public void averageWeight() { System.out.println("中国人的平均体重是:"+weight); } public void chinaGongfu() { System.out.println("我会中国功夫:坐如钟,站如松,睡如弓!"); } } package T092202; public class AmericanPeople extends People { public void speakHello() { System.out.println("你好,我是美国人!"); } public void averageHeight() { System.out.println("美国人的平均身高是:"+height); } public void averageWeight() { System.out.println("美国人的平均体重是:"+weight); } public void amercianBoxing() { System.out.println("我会美式拳击:直拳,上勾拳!"); } } package T092202; public class Test { public static void main(String[] args) { ChinaPeople chp=new ChinaPeople(); chp.height=175; chp.weight=140; chp.speakHello(); chp.averageHeight(); chp.averageWeight(); chp.chinaGongfu(); AmericanPeople amp=new AmericanPeople(); amp.setHeight(185); amp.setWeight(170); amp.speakHello(); amp.averageHeight(); amp.averageWeight(); amp.amercianBoxing(); } }
以上是关于作业-继承2的主要内容,如果未能解决你的问题,请参考以下文章
IT十八掌作业_java基础第五天_静态代码块类的继承和接口
HTML5期末大作业:餐饮美食网站设计——咖啡(10页) HTML+CSS+JavaScript 学生DW网页设计作业成品 web课程设计网页规划与设计 咖啡网页设计 美食餐饮网页设计...(代码片段