欢迎来到天天文库
浏览记录
ID:14730956
大小:37.00 KB
页数:11页
时间:2018-07-30
《面向对象设计(object oriented design )》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、面向对象设计000(Objectorienteddesign000)Basicknowledge:Simpleprinciplesandapplicationsofexceptionhandlingmechanismsin1.C++orJava.WhentheJAVAprogramviolatesthesemanticrulesofJAVA,theJAVAvirtualmachinewillrepresenttheerrorasanexception.Violationofsemanticrulesincludes2cases.Oneisthebuilt-insemanticch
2、eckintheJAVAclasslibrary.Forexample,ifthearraysubscriptisoutofbounds,theIndexOutOfBoundsExceptionwillberaised;theNullPointerExceptionobjectwillberaisedwhenaccessingthenull.Inanothercase,JAVAallowsprogrammerstoextendthissemanticcheck,whereprogrammerscancreatetheirownexceptionsandfreelychoosewh
3、entoraiseanexceptionwiththethrowkeyword.Allexceptionsaresubclassesofjava.lang.Thowable.The2.JavainterfaceisthesameanddifferentfromthevirtualclassofC++.SinceJavadoesnotsupportmultipleinheritance,andthereisapossibilitythataclassorobjectwillusemethodsorattributesthatareinseveralclassesorobjects,
4、theexistingsingleinheritancemechanismcannotmeettherequirements.Theinterfaceismoreflexiblethaninheritancebecausetheinterfacedoesnothaveanyimplementationcode.Whenaclassimplementsaninterface,theclasstoimplementtheinterfacemethodsandpropertiesofallthepropertiesoftheinterface,andinthedefaultstatei
5、sbelowpublicstatic,allthewaytothedefaultispublic.aclasscanimplementmultipleinterfaces.3.advantagesandprinciplesofgarbagecollection.2recyclingmechanismsareconsidered.AremarkablefeatureofJavalanguageisintroducedintothegarbagecollectionmechanism,memorymanagementmakesc++programmersthemosttroubles
6、omeproblemitmakesJavaprogrammerssmoothlydoneoreasilysolved,atthetimeofwritingprogramsnolongerneedtoconsidermemorymanagement.Becauseofagarbagecollectionmechanism,objectsinJavanolongerhavescopeconcepts,andonlythereferenceoftheobjecthasscope".Garbagecollectioncaneffectivelypreventmemoryleaks,and
7、effectivelyusethememoryyoucanuse.Thegarbagecollectorisusuallyusedasthethreadtorunaseparatelowlevel,unpredictablesituationsontheheapofdeadornotusedforalongtimetheobjectisclearandrecovery,callingthegarbagecollectorprogrammerscannotbereal-timega
此文档下载收益归作者所有