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

C-6 南北方饮食文化不同的案例

时间:2015-09-02 10:45:46      阅读:253      评论:0      收藏:0      [点我收藏+]

标签:

 1 /*
 2     不同地方饮食文化不同案例
 3 */
 4 class Person{
 5     public void eat(){
 6         System.out.println("吃饭");
 7     }
 8 }
 9 
10 class SouthPerson extends Person {
11     public void eat(){
12         System.out.println("吃米饭");
13     }
14     public void sell(){
15         System.out.println("经商");
16     }
17 }
18 
19 class NorthPerson extends Person {
20     public void eat(){
21         System.out.println("吃馒头");
22     }
23     public void study(){
24         System.out.println("研究");
25     }
26 }
27 
28 class DuoTaiTest{
29     public static void main(String[] args){
30         Person p = new SouthPerson();
31         p.eat();
32         System.out.println("----------");
33         
34         SouthPerson sp = (SouthPerson) p;
35         sp.eat();
36         sp.sell();
37         System.out.println("----------");
38         
39         p = new NorthPerson();
40         p.eat();
41         System.out.println("----------");
42         
43         NorthPerson np = (NorthPerson) p;
44         np.eat();
45         np.study();
46     }
47 
48 }

运行结果:

吃米饭
----------
吃米饭
经商
----------
吃馒头
----------
吃馒头
研究

 

C-6 南北方饮食文化不同的案例

标签:

原文地址:http://www.cnblogs.com/android-lyz/p/4777758.html

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