欢迎来到天天文库
浏览记录
ID:51617563
大小:1.57 MB
页数:46页
时间:2020-03-26
《Java语言程序设计10E LiangPPT习题案例13slide.ppt》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、11Chapter13AbstractClassesandInterfaces22MotivationsYouhavelearnedhowtowritesimpleprogramstocreateanddisplayGUIcomponents.Canyouwritethecodetorespondtouseractions,suchasclickingabuttontoperformanaction?Inordertowritesuchcode,youhavetoknowaboutinterfaces.Aninterfaceisfordefiningcommon
2、behaviorforclasses(includingunrelatedclasses).Beforediscussinginterfaces,weintroduceacloselyrelatedsubject:abstractclasses.33ObjectivesTodesignanduseabstractclasses(§13.2).Togeneralizenumericwrapperclasses,BigInteger,andBigDecimalusingtheabstractNumberclass(§13.3).Toprocessacalendaru
3、singtheCalendarandGregorianCalendarclasses(§13.4).Tospecifycommonbehaviorforobjectsusinginterfaces(§13.5).Todefineinterfacesanddefineclassesthatimplementinterfaces(§13.5).TodefineanaturalorderusingtheComparableinterface(§13.6).TomakeobjectscloneableusingtheCloneableinterface(§13.7).T
4、oexplorethesimilaritiesanddifferencesamongconcreteclasses,abstractclasses,andinterfaces(§13.8).TodesigntheRationalclassforprocessingrationalnumbers(§13.9).Todesignclassesthatfollowtheclass-designguidelines(§13.10).44AbstractClassesandAbstractMethodsRunCircleRectangleTestGeometricObje
5、ctGeometricObject55abstractmethodinabstractclassAnabstractmethodcannotbecontainedinanonabstractclass.Ifasubclassofanabstractsuperclassdoesnotimplementalltheabstractmethods,thesubclassmustbedefinedabstract.Inotherwords,inanonabstractsubclassextendedfromanabstractclass,alltheabstractme
6、thodsmustbeimplemented,eveniftheyarenotusedinthesubclass.66objectcannotbecreatedfromabstractclassAnabstractclasscannotbeinstantiatedusingthenewoperator,butyoucanstilldefineitsconstructors,whichareinvokedintheconstructorsofitssubclasses.Forinstance,theconstructorsofGeometricObjectarei
7、nvokedintheCircleclassandtheRectangleclass.77abstractclasswithoutabstractmethodAclassthatcontainsabstractmethodsmustbeabstract.However,itispossibletodefineanabstractclassthatcontainsnoabstractmethods.Inthiscase,youcannotcreateinstancesoftheclassusingthenewoperator.Thisclassisusedasab
8、aseclassford
此文档下载收益归作者所有