Java 继承——2
Posted jakermk
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java 继承——2相关的知识,希望对你有一定的参考价值。
创建如下三个类:(People类中的三个方法分别输出一些信息,ChinaPeople
和AmericanPeople类重写父类的三个方法)。
package text1; public class People { protected double height; protected double weight; public void speak() { System.out.println("hello"); } public void averageHeight() { System.out.println("身高"); } public void averageWeight() { System.out.println("体重"); } }
package text1; public class Chinapeople extends People { public void speak() { System.out.println("你好"); } public void averageHeight() { System.out.println("中国身高"); } public void averageWeight() { System.out.println("中国体重"); } public void chinagongfu() { System.out.println("站如松"); } }
package text1; public class Americanpeople extends People { public void speak() { System.out.println("Hello!!!!!!"); } public void averageHeight() { System.out.println("height"); } public void averageWeight() { System.out.println("weight"); } public void americanboxing() { System.out.println("拳击"); } }
package text1; public class text12 { public static void main(String[] args) { // TODO 自动生成的方法存根 People p=new People(); p.speak(); p.averageHeight(); p.averageWeight(); Chinapeople c=new Chinapeople(); c.speak(); c.averageHeight(); c.averageWeight(); c.chinagongfu(); Americanpeople a=new Americanpeople(); a.speak(); a.averageHeight(); a.averageWeight(); a.americanboxing(); } }
以上是关于Java 继承——2的主要内容,如果未能解决你的问题,请参考以下文章