java上转型对象实验分析_实验三 继承,上转型对象 之Example.java

(一)Example.java

0818b9ca8b590ca3270a3433284dd417.png

classPeople

{

protecteddoubleweight,height;

publicvoidspeakHello( )

{

System.out.println("yayawawa");

}

publicvoidaverageHeight()

{

height=173;

System.out.println("average height:"+height);

}

publicvoidaverageWeight( )

{

weight=70;

System.out.println("average weight:"+weight);

}

}

classChinaPeopleextendsPeople

{

publicvoidspeakHello( ){

System.out.println("你好,吃了吗");

}// 重写public void speakHello( )方法,要求输出类似“你好,吃了吗”

// 这样的汉语信息

publicvoidaverageHeight( ){

System.out.println("中国人的平均身高:168.78厘米");

}// 重写public void averageHeight( )方法,要求输出类似

// “中国人的平均身高:168.78厘米”这样的汉语信息

publicvoidaverageWeight( ){

System.out.println("中国人的平均体重:65公斤");

}// 重写public void averageWeight( )方法,

// 要求输出类似“中国人的平均体重:65公斤”这样的汉语信息

publicvoidchinaGongfu ()

{

System.out.println("坐如钟,站如松,睡如弓");// 输出中国武术的信息,如"坐如钟,站如松,睡如弓"等

}

}

classAmericanPeopleextendsPeople

{

publicvoidspeakHello(){

System.out.println("How do you do");

}//重写public void speakHello()方法,要求输出类似“How do you do”这样的英语信息

publicvoidaverageHeight( ){

System.out.println("average height:"+height);

}// 重写public void averageHeight( )方法

publicvoidaverageWeight( ){

System.out.println("average weight:"+weight);

}// 重写public void averageWeight( )方法

publicvoidamericanBoxing()

{

System.out.println("直拳"+"钩拳");// 输出拳击的信息,如“直拳”、“钩拳”等

}

}

classBeijingPeopleextendsChinaPeople

{

publicvoidspeakHello( ){

System.out.println("您好");

}// 重写public void speakHello( )方法,要求输出类似“您好”这样的汉语信息

publicvoidaverageHeight( ){

System.out.println("average weight:"+weight);

}// 重写public void averageHeight( )方法

publicvoidaverageWeight( ){

System.out.println("average weight:"+weight);

}// 重写public void averageWeight( )方法

publicvoidbeijingOpera()

{

System.out.println("唱脸谱");// 输出京剧的信息

}

}

publicclassExample

{

publicstaticvoidmain(String args[ ])

{

ChinaPeople chinaPeople=newChinaPeople( );

AmericanPeople americanPeople=newAmericanPeople( );

BeijingPeople beijingPeople=newBeijingPeople( );

chinaPeople.speakHello( );

americanPeople.speakHello( );

beijingPeople.speakHello( );

chinaPeople.averageHeight( );

americanPeople.averageHeight( );

beijingPeople.averageHeight( );

chinaPeople.averageWeight( );

americanPeople.averageWeight( );

beijingPeople.averageWeight( );

chinaPeople.chinaGongfu( );

americanPeople.americanBoxing( );

beijingPeople.beijingOpera( ) ;

beijingPeople.chinaGongfu( );

}

}

运行结果:

0818b9ca8b590ca3270a3433284dd417.png

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值