资源描述:
《Java语言程序设计10E LiangPPT习题案例09slide.ppt》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、1Chapter9ObjectsandClasses2MotivationsAfterlearningtheprecedingchapters,youarecapableofsolvingmanyprogrammingproblemsusingselections,loops,methods,andarrays.However,theseJavafeaturesarenotsufficientfordevelopinggraphicaluserinterfacesandlargescalesoftwaresystems.Suppo
2、seyouwanttodevelopagraphicaluserinterfaceasshownbelow.Howdoyouprogramit?3ObjectivesTodescribeobjectsandclasses,anduseclassestomodelobjects(§9.2).TouseUMLgraphicalnotationtodescribeclassesandobjects(§9.2).Todemonstratehowtodefineclassesandcreateobjects(§9.3).Tocreateob
3、jectsusingconstructors(§9.4).Toaccessobjectsviaobjectreferencevariables(§9.5).Todefineareferencevariableusingareferencetype(§9.5.1).Toaccessanobject’sdataandmethodsusingtheobjectmemberaccessoperator(.)(§9.5.2).Todefinedatafieldsofreferencetypesandassigndefaultvaluesfo
4、ranobject’sdatafields(§9.5.3).Todistinguishbetweenobjectreferencevariablesandprimitivedatatypevariables(§9.5.4).TousetheJavalibraryclassesDate,Random,andPoint2D(§9.6).Todistinguishbetweeninstanceandstaticvariablesandmethods(§9.7).Todefineprivatedatafieldswithappropria
5、tegetandsetmethods(§9.8).Toencapsulatedatafieldstomakeclasseseasytomaintain(§9.9).Todevelopmethodswithobjectargumentsanddifferentiatebetweenprimitive-typeargumentsandobject-typearguments(§9.10).Tostoreandprocessobjectsinarrays(§9.11).Tocreateimmutableobjectsfromimmuta
6、bleclassestoprotectthecontentsofobjects(§9.12).Todeterminethescopeofvariablesinthecontextofaclass(§9.13).Tousethekeywordthistorefertothecallingobjectitself(§9.14).4OOProgrammingConceptsObject-orientedprogramming(OOP)involvesprogrammingusingobjects.Anobjectrepresentsan
7、entityintherealworldthatcanbedistinctlyidentified.Forexample,astudent,adesk,acircle,abutton,andevenaloancanallbeviewedasobjects.Anobjecthasauniqueidentity,state,andbehaviors.Thestateofanobjectconsistsofasetofdatafields(alsoknownasproperties)withtheircurrentvalues.Theb
8、ehaviorofanobjectisdefinedbyasetofmethods.5ObjectsAnobjecthasbothastateandbehavior.Thestatedefinestheobject,andthebehaviorde