欢迎来到天天文库
浏览记录
ID:51963920
大小:1.52 MB
页数:46页
时间:2020-03-26
《Java语言程序设计与数据结构 基础篇原书第11版PPT及其他教辅资源13slide.ppt》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、11Chapter13AbstractClassesandInterfaces22MotivationsYouhavelearnedhowtowritesimpleprogramstocreateanddisplayGUIcomponents.Canyouwritethecodetorespondtouseractions,suchasclickingabuttontoperformanaction?Inordertowritesuchcode,youhavetoknowaboutinterfaces.Aninterfaceisfordefiningcommonbeha
2、viorforclasses(includingunrelatedclasses).Beforediscussinginterfaces,weintroduceacloselyrelatedsubject:abstractclasses.33ObjectivesTodesignanduseabstractclasses(§13.2).Togeneralizenumericwrapperclasses,BigInteger,andBigDecimalusingtheabstractNumberclass(§13.3).ToprocessacalendarusingtheC
3、alendarandGregorianCalendarclasses(§13.4).Tospecifycommonbehaviorforobjectsusinginterfaces(§13.5).Todefineinterfacesanddefineclassesthatimplementinterfaces(§13.5).TodefineanaturalorderusingtheComparableinterface(§13.6).TomakeobjectscloneableusingtheCloneableinterface(§13.7).Toexplorethes
4、imilaritiesanddifferencesamongconcreteclasses,abstractclasses,andinterfaces(§13.8).TodesigntheRationalclassforprocessingrationalnumbers(§13.9).Todesignclassesthatfollowtheclass-designguidelines(§13.10).44AbstractClassesandAbstractMethodsRunGeometricObjectCircleRectangleTestGeometricObjec
5、t55abstractmethodinabstractclassAnabstractmethodcannotbecontainedinanonabstractclass.Ifasubclassofanabstractsuperclassdoesnotimplementalltheabstractmethods,thesubclassmustbedefinedabstract.Inotherwords,inanonabstractsubclassextendedfromanabstractclass,alltheabstractmethodsmustbeimplement
6、ed,eveniftheyarenotusedinthesubclass.66objectcannotbecreatedfromabstractclassAnabstractclasscannotbeinstantiatedusingthenewoperator,butyoucanstilldefineitsconstructors,whichareinvokedintheconstructorsofitssubclasses.Forinstance,theconstructorsofGeometricObjectareinvokedintheCircleclassan
7、dtheRectangleclass.77abstractclasswithoutabstractmethodAclassthatcontainsabstractmethodsmustbeabstract.However,itispossibletodefineanabstractclassthatcontainsnoabstractmethods.Inthiscase,youcannotcreateinstancesoftheclassusingthenewoperator.Thisclassisusedasabaseclassford
此文档下载收益归作者所有