继承—people

Posted 唐枫

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了继承—people相关的知识,希望对你有一定的参考价值。

 1 public class People {
 2     
 3     private double height;//身高
 4     private double weight;//体重
 5 
 6     public double getHeight() {
 7         return height;
 8     }
 9 
10     public void setHeight(double height) {
11         this.height = height;
12     }
13 
14     public double getWeight() {
15         return weight;
16     }
17 
18     public void setWeight(double weight) {
19         this.weight = weight;
20     }
21 
22     
23     //方法打招呼
24     public void speakHello(){
25         System.out.println("hello !");
26     }
 1 //extends  继承
 2 public class ChinaPeople extends People {
 3 
 4     public void ChinaKongFu(){
 5         System.out.println("坐如钟,站如松。");
 6     }
 7     //重写   覆盖
 8     public void speakHello(){
 9         System.out.println("你好!");
10     }
11 }
1 public class AmericanPeople extends People {
2 
3     public void americanBoxing(){
4         System.out.println("直拳,左勾拳");
5     }
6 }
 1 public class Text_People {
 2 
 3     public static void main(String[] args) {
 4         People p1 = new People();
 5         p1.speakHello();
 6 
 7         ChinaPeople p2 = new ChinaPeople();
 8         p2.speakHello();
 9         p2.ChinaKongFu();
10         
11         
12         
13     }
14 }

运行:

以上是关于继承—people的主要内容,如果未能解决你的问题,请参考以下文章

继承 2—people

带有哈希片段的锚未导航到匹配的 id

Python 继承和组合 接口

java基础,继承类题目:编写一个Java应用程序,该程序包括3个类:Monkey类People类和主类 E

编程打卡: C++ 语言程序设计: 继承与派生: 习题

继承-monkey