创建如下三个类:(People类中的三个方法分别输出一些信息,ChinaPeople 和AmericanPeople类重写父类的三个方法)。

Posted 戳记

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了创建如下三个类:(People类中的三个方法分别输出一些信息,ChinaPeople 和AmericanPeople类重写父类的三个方法)。相关的知识,希望对你有一定的参考价值。

创建如下三个类:(People类中的三个方法分别输出一些信息,ChinaPeople

和AmericanPeople类重写父类的三个方法)。

技术分享

ackage com.chuoji.text01;

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 com.chuoji.text01;

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 com.chuoji.text01;

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 com.chuoji.text01;

public class Text {

    public static void main(String[] args) {

        ChinaPeople C=new ChinaPeople();
        C.height=175;
        C.weight=65;
        C.speakHello();
        C.averageHeight();
        C.averageWeight();
        C.chinaGongfu();
        
        AmericanPeople M =new AmericanPeople();
        M.height=180;
        M.weight=75;
        M.speakHello();
        M.averageHeight();
        M.averageWeight();
        M.amercianBoxing();
        

    }

}

技术分享

以上是关于创建如下三个类:(People类中的三个方法分别输出一些信息,ChinaPeople 和AmericanPeople类重写父类的三个方法)。的主要内容,如果未能解决你的问题,请参考以下文章

19.创建如下三个类:(People类中的三个方法分别输出一些信息,ChinaPeople 和AmericanPeople类重写父类的三个方法)。

继承-people

继承 2—people

作业-继承2

Java 继承——2

java 继承练习题2