Java实验报告样本.doc

上传人:飞****2 文档编号:56714440 上传时间:2022-11-03 格式:DOC 页数:5 大小:61.50KB
返回 下载 相关 举报
Java实验报告样本.doc_第1页
第1页 / 共5页
Java实验报告样本.doc_第2页
第2页 / 共5页
点击查看更多>>
资源描述

《Java实验报告样本.doc》由会员分享,可在线阅读,更多相关《Java实验报告样本.doc(5页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。

1、信息科学与工程学院 Java程序设计 上机实验报告专业班级 电技电信0901 姓 名 刘雄楚 学 号 0 实验时间 2011 年 9 月 30 日 指导教师 程骅 成 绩 实验名称面向对象程序设计的继承、多态等特性的练习实验目的1) 掌握类的继承机制。2) 熟悉类中成员变量和方法的访问控制。3) 熟悉方法或构造方法多态性。4) 熟悉接口的定义方法。1class Personpublic String name;public char sex;public int age; Person(String name,char sex,int age)this.name=name;this.sex=s

2、ex;this.age=age;class Student extends Personpublic String classno;public String sno;public void updateAge(int age) this.age=age;public String toString()System.out.println(this.name+ +this.sex+ +this.age+ +this.classno+ +this.sno);return this.name+ +this.sex+ +this.age+ +this.classno+ +this.sno;Stude

3、nt(String name,char sex,int age,String classno,String sno)super(name,sex,age);this.classno=classno;this.sno=sno;public class TestStudentPersonpublic static void main(String args)Student s1=new Student(jeck,n,20,2);s1.updateAge(21);s1.toString();2public class TestVirtualInvoke static void doStuff(Sha

4、pe s) s.draw(); public static void main(String args) Circle c=new Circle(); Triangle t=new Triangle(); Line l=new Line(); doStuff(c); doStuff(t); doStuff(l); class Shapevoid draw()System.out.println(Shape Drawing);class Circle extends Shapevoid draw()System.out.println(Shape Circle);class Triangle e

5、xtends Shapevoid draw()System.out.println(Shape Triangle);class Line extends Shapevoid draw()System.out.println(Shape Line); 使用抽象类abstractabstract class Shapeabstract void draw(); class Circle extends Shapevoid draw()System.out.println(Shape Circle); class Triangle extends Shapevoid draw()System.out

6、.println(Shape Triangle); class Line extends Shapevoid draw()System.out.println(Shape Line);使用interface接口方法interface Shapepublic void draw(); class Circle implements Shape publicvoid draw()System.out.println(Shape Circle); class Triangle implements Shape public void draw()System.out.println(Shape Tr

7、iangle); class Line implements Shape publicvoid draw()System.out.println(Shape Line); 思考题:import java.util.*;abstract class Employee String name; long no; static long id=1000; abstract double getPay(); Employee(String name) this.name=name;id=id+1; ;class Manager extends Employee double pay=8000;doub

8、le getPay()return 8000; Manager(String name)super(name); no=id; public String toString()return name:+name+ no:+no+ pay:8000;class Sale extends Employee long saleNum; double getPay()return saleNum*0.04;Sale(String name,long saleNum)super(name); no=id; this.saleNum=saleNum; public String toString()ret

9、urn name:+name+ no:+no+ pay:+getPay();class Tech extends Employee long salaryHours; double getPay()return salaryHours*100; Tech(String name,long salaryHours)super(name); no=id; this.salaryHours=salaryHours; public String toString()return name:+name+ no:+no+ pay:+getPay();class EmployApp public stati

10、c void main(String args)Vector s=new Vector();Employee em;double numPay=0;s.addElement(new Sale(aa,);s.addElement(new Sale(bb,);s.addElement(new Tech(cc,35);s.addElement(new Tech(dd,30);s.addElement(new Manager(ee);Enumeration e=s.elements();while(e.hasMoreElements() em=(Employee)e.nextElement();numPay=numPay+em.getPay(); System.out.println(em);System.out.println(总工资:+numPay);心得:此次试验更多更广的运用了类的继承这一特性,使得程序更简单易读,同时运用到了抽象类与接口的使用方法,总体而言是上一次实验的引申,进一步加深了知识的运用,学习了更多的方法以及构造方法的运用方式。

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 教案示例

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知得利文库网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号-8 |  经营许可证:黑B2-20190332号 |   黑公网安备:91230400333293403D

© 2020-2023 www.deliwenku.com 得利文库. All Rights Reserved 黑龙江转换宝科技有限公司 

黑龙江省互联网违法和不良信息举报
举报电话:0468-3380021 邮箱:hgswwxb@163.com