教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 文库大全 > 资格考试 >

Chapter 6 Objects and Classes

来源:网络收集 时间:2026-02-18
导读: Chpaer 6t Ojbect snadCl asse s1 otMvitionsafAtrele aning rhte rpceeding caphert,syo u arec apabe lo fsovilg mann pyrogrmamng irpbloesmusin sgleectonis,l oos,p an detmhods How.evr,e htees Jva afaterues are onts ffucieintfor dev leopnig grph

Chpaer 6t Ojbect snadCl asse

s1

otMvitionsafAtrele aning rhte rpceeding caphert,syo u arec apabe lo fsovilg mann pyrogrmamng irpbloesmusin sgleectonis,l oos,p an detmhods How.evr,e htees Jva afaterues are onts ffucieintfor dev leopnig grphicaa lseu rintrefcasea dnl rgea salc esotwfaersy tess.mSu ppseo yu owat tnod velop e graaphicla sur enitrfaec ase hosn weblo. wHowdo ou pyroramgit?

2

bjectOvies

oT escrdieb ojebtcsand casless ,na dse culsases t omdoel ojbcets( 8.2)§.To us e MUL gaphrial nctatooins to esdcibr elasscs aedn bjoctes(§ .8). 2T doeomnsrtte daefinni glascse asd ncraetng objicte s§8.(3) To.c reae objtecs tsiun gcontsructos r(§.48) .T ocaescsob jetcsvi oajbect rfereencev araibls e§(.85). o dTeife n aerefrecn eavrabli esuni ag erfreence ypte( §8.5.)1. To cacessan obejc’t sadt aadnm thods euinsg hetob ecj temmer bacecs spoeatror( ).(§ .582)..T odfene idta afiedlsof erfeercent pye asd nssagn dieaufltv aleu fso anr objct’s daea tiefdsl (8§5..).3T oisditgunsi hetbewneo jebc rtfeeernc eavirabelsa n dprimiitevdat a ytep avrailbse §(85.4..) oT sue lcassse atDe,R adon, mna JFdram enit h eJaavlibr ray( 8.§).6T oditsnguishib etewen intsnaec ndastat c ivriaables adnm ehtdo s§8.7() T. doeife prnivteada ta fiedls wti apphrpriaot eeg antds e methots (d8§.)8 T. oencaspultea adtafiel d st omaek lcasesse ay st oaintmian (§89.) To. deelvp methoos dwthiobje ctar gument asdndiff reetinae betwten epimitrveitye pagurmetsn nd abojcettyp- areguments(§ 81.0). T sotoe ardn rpcosse bjoctse in raayrs( 8§11)..

36.

1OO P rogrmaimg nCncoptsebOjct-orientee pdogrrmmanig(O P) Oinolvves prorgmmaignu sng iboejts. Acn ojebtc reperesnst naen itty in ht eerl aorwd thaltca nbe di stinclyt deinified. Forte amxlpe a ,stduent, ade ks, a icclre a,b utont ,nad vee nal on caa nal lbe viewde sa ojbecst A. onjebtc as h uanique dientty, state,ia n bdehvairso .hTe tsta oe fn aojecbt onsicstso afset fodata f eidsl (las konowna s porerpites )itw thehr icrrent uvaules .Teh beahvoirof a n objec ts idefind be ays teof mtheos.d4

6.2Obj cetsCalssNa me: irclCeDta aFeidls: raids iu _s______M theods:g eAtera

Aclass etmlate

Circlpe Ojebt cD1ata ieldFs: raids us 10i

Cirle cOjbct e2aDtaF ielsd :radusi is 25Ciclre Obecj t3Daa Ftiels: daridu ssi125

hTereo bjetcs o tfe Chirle class

Ac objnec thasbo th satate nd aehbaviro. hTe tsta eefinesd he tojecbt, nd theabehavior def ies wnat thhe obejtc oesd.5

lasCesslasCess re aocntrustsct ha dtfeine obejtscof t h easem ytp. A Jeva alcsasuse s arivables o tefdnied atafi led sand mthoed sotdef ienb eahiorvs .Adidiotnall, aycl ass povirdsea s pecality ep fo ethmdos ,kownn a csontsrctuor, shwchia er nivoed kto consrtcuto jbctesfr m ohet lcsa.s

Cl6asesslcss Caircel{ /** he raTiudso f tis hicrlc */e doblue adruis = .1;0 **/ Contsruc a tciclr obeejc *t /iCclr() {e} */*Const uctr a cricl oejbcte */Cir celdou(lb enewRdaui)s{ rdiuas = neRaw

diu;s} /**R teur the anraeof hits cricl e*/ duobe lgetAre()a {re urntr adis u radi*su 3*.41195 ;} }7

ataDfie d

ClnsoructtosrMethdo

ML CUasl siagDarUMm CLlass DigramaC ricleradius: odbul Ciecrel)( irClcen(weRadius:doub l)e egArta(): eduolbeCals nsmeaD ta afiles dConstrcuotr ans mdthodescicrel: C1ircelardus =i .1

circl02:e iCclerradisu 25=cirlce3 :Ciclerradis = u215UMLn ottainof orob ects

8j

6.3 xEampel :eDinifn Cglases snadC retaig nbOjects bOejcivet:Deonstmart ercaeitngo jectb, sccesaingsda ta,a dn sing umtehds.

ToestiCrlc1eRnu

9

Exampl: DefeninigCla sse ands rCeaitngO jecbts bOjecivte:Demnsortae trectaig onbjctes,acces sig danat, and usnigm theos.dTVTetsTVR u

1n

0

6. 4onsCturtcosCrrclie) ( } {onstruCctorsar eas eciaplk id nofm teodh sthtaare i vokndet conotrsut cboecjts.Circle(odble newuadiusR) {ra iusd =n weadiRs; u

11}

Cosnrtctousr, octn.A ocstnructro ith wno aparemers ts ireefredr otas aonarg- onctrscturo.· Con stucrotr mssu htvae ht saeem anem as te hlcas itsesfl.· Co nsruttorcs don to haeva retrn tuyep—nto evnev oid

.· oCsntrcuors trea ivoned uksni tgeh nwe operaotr whnean bojetc s criaeedt. Consrtuctros paylt eh ole of inirtiailzng iojebcst.12

rCeatngi bOjetc ssiUg CnnsotucrtronsewC lssaNae(m;

)xamElp:enew iCcrel();ne Cwrcli(e.5);03

1

DfeuatlC ostrncutorA lcas masy b decleradew ithoutcon tsrcutors I.n his tcsae a no,ar-gc osntuctror wthi a nempt boyd yi imslipctli yedlarce di thne class Thi. scosnrtuctor ,allcde dafealtu cnstrocuotr,i sp rovide datoumatialcl yolnyif onc nsotucrors aret xepicitlly ecldaed rinthe lcsa.s14

Declarin Ogjbet Refcreecn eVriableasTor feeenre ac onbject ,asisgnt heobject to a reefencr veraiblea.T oedcarl ea erfreecenvari ale,b us the eyntas:x lCasNsam oebejcRetVfar;Exmalpe:irCle cmyirClce;51

eDcarlnig/reatiCn gbOjctsein a SignleSt peCaslsaNem ojbctRefVea r new=C asslNam();erCeaet na bjeot

cEaxmpel:

ssAingob ectj reerenfecCrilecmyC rilec= ewn iCcrl();

e61

.5 6cceAssin Ogjebtcs Reefercingnthe o bectjs ’dta:aobjectefRaV.radta

.eg,. yCimrlc.redius aInvkoin thegob jetc’sm ehodt:obejtceRVfa.methordNaem(rgumaetn)seg.., mCyircl.egtArea()e1

7

ainmtaoniTare CcodeDceale ryCmricl meyCrcli noeva lue

Crcli meyircCle= n we iCcrle(50.;)SCircle yourCicle = ren wiCrlc(); eouryCirlc.readui =s 010;18

animtaoi

Tnare coCde,c otn.myCrclieno alue

Cvrilcem Cyrcli =en ewC iclre5(.0;C)rcle iyoruirclC =e ne Cirwlec); (yuorirCle.crdais =u 001

:; Ciclerradis: u.0

C5eart eac icrl

e91

…… 此处隐藏:3277字,全部文档内容请下载后查看。喜欢就下载吧 ……
Chapter 6 Objects and Classes.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wenku/107016.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)