Chapter 6 Objects and Classes
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字,全部文档内容请下载后查看。喜欢就下载吧 ……相关推荐:
- [资格考试]石油钻采专业设备项目可行性研究报告编
- [资格考试]2012-2013学年度第二学期麻风病防治知
- [资格考试]道路勘测设计 绪论
- [资格考试]控烟戒烟知识培训资料
- [资格考试]建设工程安全生产管理(三类人员安全员
- [资格考试]photoshop制作茶叶包装盒步骤平面效果
- [资格考试]授课进度计划表封面(09-10下施工)
- [资格考试]麦肯锡卓越工作方法读后感
- [资格考试]2007年广西区农村信用社招聘考试试题
- [资格考试]软件实施工程师笔试题
- [资格考试]2014年初三数学复习专练第一章 数与式(
- [资格考试]中国糯玉米汁饮料市场发展概况及投资战
- [资格考试]塑钢门窗安装((专项方案)15)
- [资格考试]初中数学答题卡模板2
- [资格考试]2015-2020年中国效率手册行业市场调查
- [资格考试]华北电力大学学习实践活动领导小组办公
- [资格考试]溃疡性结肠炎研究的新进展
- [资格考试]人教版高中语文1—5册(必修)背诵篇目名
- [资格考试]ISO9001-2018质量管理体系最新版标准
- [资格考试]论文之希尔顿酒店集团进入中国的战略研
- 全国中小学生转学申请表
- 《奇迹暖暖》17-支2文学少女小满(9)公
- 2019-2020学年八年级地理下册 第六章
- 2005年高考试题——英语(天津卷)
- 无纺布耐磨测试方法及标准
- 建筑工程施工劳动力安排计划
- (目录)中国中央空调行业市场深度调研分
- 中国期货价格期限结构模型实证分析
- AutoCAD 2016基础教程第2章 AutoCAD基
- 2014-2015学年西城初三期末数学试题及
- 机械加工工艺基础(完整版)
- 归因理论在管理中的应用[1]0
- 突破瓶颈 实现医院可持续发展
- 2014年南京师范大学商学院决策学招生目
- 现浇箱梁支架预压报告
- Excel_2010函数图表入门与实战
- 人教版新课标初中数学 13.1 轴对称 (
- Visual Basic 6.0程序设计教程电子教案
- 2010北京助理工程师考试复习《建筑施工
- 国外5大医疗互联网模式分析




