zoukankan      html  css  js  c++  java
  • 子类与继承:实验1


    package Example;
    
    public class People {
    	double height,weight;
    	People(){
    		height=0;
    		weight=0;
    	}
    	People(double height, double weight){
    		this.height=height;
    		this.weight=weight;
    	}
    	void speakHello(){
    		System.out.println("yayayaya");
    	}
    	void averageHeight(){
    		System.out.println("People averageheight:"+height);
    	}
    	void averageWeight(){
    		System.out.println("People averageweight:"+weight);
    	}
    }
    



    package Example;
    
    public class ChinaPeople extends People{
    	public ChinaPeople(){
    		super();
    	}
        public ChinaPeople(double height, double weight){
    		super(height, weight);
    	}
    	public void speakHello(){
    		System.out.println("你好");
    	}
    	public void averageHeight(){
    		System.out.println("中国人的平均身高:"+height);
    	}
    	public void averageWeight(){
    		System.out.println("中国人的平均体重:"+weight);
    	}
    	public void chinaGongfu(){
    		System.out.println("坐如钟 ,站如松 ,睡如松");
    	}
    }

    package Example;
    
    public class AmericanPeople extends People{
    	public  AmericanPeople(){
    		super();
    	}
    	public	AmericanPeople(double height, double weight){
    		super(height, weight);
    	}
    	public void speakHello(){
    		System.out.println("How do you do?");
    	}
    	public void averageHeight(){
    		System.out.println("Ameriacan's average height:"+height);
    	}
    	public void averageWeight(){
    		System.out.println("Ameriacan's average weight:"+weight);
    	}
    	public void americanBoxing(){
    		System.out.println("直拳,勾拳,组合拳");
    	}
    }
    

    package Example;
    
    public class BeijingPeople extends ChinaPeople{
    	public BeijingPeople(){
    		super();
    	}
    	public BeijingPeople(double height, double weight){
    		super(height, weight);
    	}
    	public void speakHello(){
    		System.out.println("你好");
    	}
    	public void averageHeight(){
    		System.out.println("北京人的平均身高:"+height);
    	}
    	public void averageWeight(){
    		System.out.println("北京人的平均体重:"+weight);
    	}
    	public void beijingOpera(){
    		System.out.println("花脸,青衣,花旦和老生");
    	}
    }

    import Example.*;
    
    public class main_ {
    
    	public static void main(String[] args) {
    		ChinaPeople chinese=new ChinaPeople(168.18,65);
    		AmericanPeople american=new AmericanPeople(176,75);
    		BeijingPeople beijings=new BeijingPeople(172.5, 70);
    		
    		chinese.speakHello();
    		american.speakHello();
    		beijings.speakHello();
    		chinese.averageHeight();
    		american.averageHeight();
    		beijings.averageHeight();
    		chinese.averageWeight();
    		american.averageWeight();
    		beijings.averageWeight();
    		chinese.chinaGongfu();
    		american.americanBoxing();
    		beijings.beijingOpera();
    		beijings.chinaGongfu();
    	}
    
    }


  • 相关阅读:
    3D Computer Grapihcs Using OpenGL
    3D Computer Grapihcs Using OpenGL
    3D Computer Grapihcs Using OpenGL
    3D Computer Grapihcs Using OpenGL
    转:RealThinClient LinkedObjects Demo解析
    转:RealThinClient (RTC)是什么?
    DataSanp的控制老大-DSServer
    5.Firedac错误信息
    4.FireDAC组件快照 二
    3.FireDAC组件快照
  • 原文地址:https://www.cnblogs.com/WALLACE-S-BOOK/p/9732339.html
Copyright © 2011-2022 走看看