资源描述:
《实验指导书:实验 继承与多态(一)》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、西安邮电大学(计算机学院)面向对象程序设计JAVA课内实验报告实验名称: 继承与多态(一)专业名称: 软件工程班级:软件1501学生姓名:冀潘婷学号(8位):04153026指导教师:张德慧实验时间:2016.10.21一.实验目的及实验环境1理解子类、父类的概念,掌握子类继承父类的方法。2理解成员变量的隐藏和方法重写。3会使用super关键字操作被隐藏的成员变量和方法。4了解final类和final方法的作用。5理解protected修饰符的作用和用法。二.实验内容1基本内容(实验前请及时熟悉如下相关内容)1)类的继承:定义子类2)使用super关键字调用父类方法3)
2、方法覆盖overriding:覆盖Object类的toString()方法4)练习使用ArrayList类的方法5)练习覆盖Object类的equals()方法2综合实验:2.1(Y.DanielLiang英文版八版P403:11.1)(TheTriangleclass)DesignaclassnamedTrianglethatextendsGeometricObject.Theclasscontains:■Threedoubledatafieldsnamedside1,side2,andside3withdefaultvalues1.0todenotethreesid
3、esofthetriangle.■Ano-argconstructorthatcreatesadefaulttriangle.■Aconstructorthatcreatesatrianglewiththespecifiedside1,side2,andside3.■Theaccessormethodsforallthreedatafields.■AmethodnamedgetArea()thatreturnstheareaofthistriangle.■AmethodnamedgetPerimeter()thatreturnstheperimeterofthistri
4、angle.■AmethodnamedtoString()thatreturnsastringdescriptionforthetriangle.Fortheformulatocomputetheareaofatriangle,seeExercise2.21.ThetoString()methodisimplementedasfollows:return"Triangle:side1="+side1+"side2="+side2+"side3="+side3;DrawtheUMLdiagramfortheclassesTriangleandGeometricObject
5、.Implementtheclass.WriteatestprogramthatcreatesaTriangleobjectwithsides1,1.5,1,coloryellowandfilledtrue,anddisplaysthearea,perimeter,color,andwhetherfilledornot.(不要求画出UML图)2.2(Y.DanielLiang英文版八版P403:11.2)(ThePerson,Student,Employee,Faculty,andStaffclasses)DesignaclassnamedPersonanditstwo
6、subclassesnamedStudentandEmployee.MakeFacultyandStaffsubclassesofEmployee.Apersonhasaname,address,phonenumber,andemailaddress.Astudenthasaclassstatus(freshman,sophomore,junior,orsenior).Definethestatusasaconstant.Anemployeehasanoffice,salary,anddatehired.DefineaclassnamedMyDatethatcontai
7、nsthefieldsyear,month,andday.Afacultymemberhasofficehoursandarank.Astaffmemberhasatitle.OverridethetoStringmethodineachclasstodisplaytheclassnameandtheperson’sname.DrawtheUMLdiagramfortheclasses.Implementtheclasses.WriteatestprogramthatcreatesaPerson,Student,Employee,Facu