子类与继承:实验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();
}
}
posted on 2017-11-11 09:52 MACHINE_001 阅读(192) 评论(0) 编辑 收藏 举报