77范文网 - 专业文章范例文档资料分享平台

java面向对象分析与设计复习(全答案版)(6)

来源:网络收集 时间:2020-06-24 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

}

继承

模板代码

Example.java

class People {

protected double weight,height; public void speakHello() {

System.out.println(\ }

public void averageHeight() {

height=173;

System.out.println(\ }

public void averageWeight() {

weight=70;

System.out.println(\ } }

class ChinaPeople extends People {

public void speakHello() { System.out.println(\你好,吃饭了吗?\

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

//汉语信息

public void averageHeight() { height=173; System.out.println(\中国人的平均身高:\厘米\ } //重写public void averageHeight()方法,要求输出类似

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

public void averageWeight() {

weight=67.34; System.out.println(\中国人的平均体重:\公斤\

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

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

System.out.println(\坐如钟,站如松,睡如弓\//输出中国武术的信息,例如:\坐如钟,站如松,睡如弓\等 } }

class AmericanPeople extends People {

public void speakHello() { System.out.println(\ou do\ } //重写public void speakHello()方法,要求输出类似

//“How do you do”这样的英语信息。

public void averageHeight()

{ height=188; System.out.println(\ } //重写public void averageHeight()方法

public void averageWeight()

{ weight=80.23; System.out.println(\ } //重写public void averageWeight()方法

public void americanBoxing() {

System.out.println(\直拳、钩拳\//输出拳击的信息,例如,“直拳”、“钩拳”等 } }

class BeijingPeople extends ChinaPeople {

public void speakHello() {

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

public void averageHeight()

{ height=16; System.out.println(\北京人的平均身高:\厘米\ } //重写public void averageHeight()方法

public void averageWeight()

{ weight=6;

System.out.println(\北京人的平均体重:\公斤\ } //重写public void averageWeight()方法

public void beijingOpera() {

System.out.println(\京剧术语\//输出京剧的信息 } }

public class Example {

public static void main(String args[]) {

ChinaPeople chinaPeople=new ChinaPeople();

AmericanPeople americanPeople=new AmericanPeople(); BeijingPeople beijingPeople=new BeijingPeople(); 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(); } }

上转型对象

模板代码 HardWork.java

abstract class Employee {

public abstract double earnings(); }

class YearWorker extends Employee {

public double earnings() { return 50000.456;

} //重写earnings()方法 }

class MonthWorker extends Employee {

public double earnings() { return 12*2300; } //重写earnings()方法。 }

class WeekWorker extends Employee {

public double earnings() { return 52*500; }//重写earnings()方法。 }

class Company {

Employee[] employee; double salaries=0;

Company(Employee[] employee) {

this.employee=employee; }

public double salariesPay() {

salaries=0;

for(int i=0;i

public class HardWork {

public static void main(String args[]) {

Employee[] employee=new Employee[20]; for(int i=0;i

if(i%3==0)

employee[i]=new WeekWorker(); else if(i%3==1)

employee[i]=new MonthWorker(); else if(i%3==2)

employee[i]=new YearWorker(); }

Company company=new Company(employee);

System.out.println(\公司年工资总额:\ } }

接口回调

模板代码 Road.java

interface ComputerWeight {

public double computeWeight(); }

class Television implements ComputerWeight { public double computeWeight() { return 45.5; } //实现computeWeight()方法。 }

class Computer implements ComputerWeight { public double computeWeight() { return 65.5; } //实现computeWeight()方法。 }

class WashMachine implements ComputerWeight { public double computeWeight() { return 145; } //实现computeWeight()方法。 } class Car

{ ComputerWeight[] goods; double totalWeights=0; Car(ComputerWeight[] goods) {

this.goods=goods; }

public double getTotalWeights() {

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说教育文库java面向对象分析与设计复习(全答案版)(6)在线全文阅读。

java面向对象分析与设计复习(全答案版)(6).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/jiaoyu/1125145.html(转载请注明文章来源)
上一篇:桥面混凝土铺装层施工
下一篇:城建史
Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: