zoukankan      html  css  js  c++  java
  • 编写一个主类,主类中含有四个类,

    /*编写一个java应用程序,程序中有四个类:People,ChinaPeople,AmericanPeople,BeijingPeople,
    people类有访问权限是protected的double类型的weight和height以及public void speakHello();
    public void averageHeight(),public void averageWeight()方法。
    Chinapeople类是people的子类,新增public void gongfu()方法,以及重写public void speakHello();
    public void averageHeight(),public void averageWeight()方法。
    Americanpeople类是people的子类,新增 public void americanBoxing(),
    以及重写public void speakHello();
    public void averageHeight(),public void averageWeight()方法。
    BeijingPeople类是Chinapeople的子类,新增 public void Opera(),
    以及重写public void speakHello();public void averageHeight(),
    public void gongfu()方法,public void averageWeight()方法。*/
         class People{
             protected double height;
             protected double weight;
             public void speakHello(){
                 System.out.println("hello");
             }
             public void averageHeight(){}
             public void averageWeight(){}
         }
         class AmericanPeople extends People{
             public void speakHello(){
                 System.out.println("american i");
             }
             public void averageHeight(){}
             public void averageWeight(){}
             public void americanBoxing(){}
         }
         class ChinaPeople extends People{
             public void speakHello(){
                 System.out.println("china hi");
             }
             public void averageHeight(){}
             public void averageWeight(){}
             public void chinaGongfu(){}
             
         }
         class BeijingPeople extends ChinaPeople{
             public void speakHello(){
                 System.out.println("BEIJING HI");
             }
             public void averageHeight(){}
             public void averageWeight(){}
             public void chinaGongfu(){}
             public void beijingOpera(){}
             
         }
         public class Alei {
             public static void main(String []args){
                //创建 子类AmericanPeople的一个实例对象,使用默认构造法
                 AmericanPeople a=new AmericanPeople();
                 //方法重写
                 a.speakHello();
                 a.averageHeight();
                 a.averageWeight();
                //创建子类ChinaPeople的一个实例对象,使用默认构造法
                 ChinaPeople b=new ChinaPeople();
                 //方法重写
                 b.speakHello();
                 b.averageHeight();
                 b.averageWeight();
                 //创建子类BeijingPeople的实例对象,使用默认构造法
                 BeijingPeople c=new BeijingPeople();
                 //方法重写
                 c.speakHello();
                 c.averageHeight();
                 c.averageWeight();
                 c.chinaGongfu();
    }
    }

    运行结果如下:

    american i
    china hi
    BEIJING HI
  • 相关阅读:
    SVN操作异常
    VS2010安装MVC3
    (转)游戏类型
    (转)32位汇编指令 寄存器
    (转)#pragma 用法
    (转)UI库
    (转)简单实用的网游服务器架构
    (转)一个客户端网游市场分布的数据
    (转)源于魔兽!《植物大战僵尸》成功奥秘
    (转)【分析】中国网游行业上市公司投资分析之网易
  • 原文地址:https://www.cnblogs.com/Angella/p/6146511.html
Copyright © 2011-2022 走看看