欢迎来到天天文库
浏览记录
ID:41392073
大小:83.07 KB
页数:15页
时间:2019-08-24
《9、Java面向对象之继承和多态作业题》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、Java面向对象之继承和多态作业题2011/9/23•上机要求:使用Eclipse编写主题类、回复类要求如下:■主题类继承帖子类,并增加属性:主题id,版块id9回复类继承帖子类,并增加属性:回复id,主题id9在帖子类中实现多态-使用super调用父类构造方法•阶段一:■需求说明:■创建主题类,继承帖子类类名Topic属性topield:intboardld:int类名Tip属性title:Stringcontent:StringpublishTime:Stringuid:int方法getlnfoO:void⑨实现思路及关V
2、:代码:1、创建主题类:Topic,继承帖子类:Tip2、增加以下属性主题id:inttopield版块id:intboardld3、添加setter/getter方法4、使用从帖子类继承来的getlnfoO方法,输岀主题信息packagecom.workit•part3;publicclassTopic{privateinttopield;privateintboardTd;publicTopic(inttopield,intboardTd){super();this.topield=topield;this.boardTd
3、=boardTd;packagecom.workit・p3rt3;publicclassTipextendsTopic{publicTip(inttopicld,intboardTd){super(topicld,boardTd);//TODOAuto-generatedconstructorstub}privateStringtitle;privateStringcontent;privateStringpublishTime;publicStringgetTitle(){returntitle;}publicvoidset
4、Title(Stringtitle){this.tit*=title;}publicStringgetContent(){returncontent;}publicvoidsetContent(Stringcontent){this.content=content;}publicStringgetPublishTime(){returnpublishTime;}publicvoidsetPublishTime(StringpublishTime){this•publishTime=publishTime;}publicvoid
5、title(){System・out・printin("巾占子标题:t”);}publicvoidcontent(){System.out.printIn("巾占子内容:t”);}publicvoidpublishTime(){System,out.printin("发帖时间:t,f);•阶段二:⑨需求说明:1、创建回复类:Reply,继承帖子类:Tip2、增加以下属性回复id:intreplyld主题id:inttopicld3、添加setter/getter方法4、使用从帖子类继承来的getlnfo()方法,输出回复
6、信息packagecom.workit.part3;publicclassReply{privateinttopicld;privateintboardld;privateintreplyld;publicintsetTopicId(inttopicld){returntopicld;}publicvoidgetTopicId(){this.topicld=topicld;}publicintsetBoardld(intboardld){returnboardld;}publicvoidgetBoardld(){this.bo
7、ardld=boardld;}publicintsetReplyld(intreplyld){returnreplyld;}publicvoidgetReply(){this.replyld=replyld;}}packagecom.workit.part3;publicclassTip2extendsReply{privateSt:ringtitle;privateStringcontent;privateStringpublishTime;publicStringsetTitle(Stringtitle){returnti
8、tle;}publicvoidgetTitle(){this.title=title;}publicStringsetContent(Stringcontent){returntitle;}publicvoidgetContent(){七his.content=content
此文档下载收益归作者所有