zoukankan      html  css  js  c++  java
  • C-6 南北方饮食文化不同的案例

     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 }

    运行结果:

    吃米饭
    ----------
    吃米饭
    经商
    ----------
    吃馒头
    ----------
    吃馒头
    研究
    
  • 相关阅读:
    es6 简介
    npm 快速开发技巧
    css清除浮动方法
    mui 总结
    7种 JS 创建对象的经典方式
    JavaScript 的 this 原理
    使用定时器
    dom 操作及方法
    JavaScript的6种继承方式及其优缺点
    贪吃蛇游戏代码
  • 原文地址:https://www.cnblogs.com/android-lyz/p/4777758.html
Copyright © 2011-2022 走看看