码迷,mamicode.com
首页 > 其他好文 > 详细

继承—people

时间:2016-05-23 09:00:02      阅读:118      评论:0      收藏:0      [点我收藏+]

标签:

 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

标签:

原文地址:http://www.cnblogs.com/ouyangtangfeng99/p/5518665.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!