0% found this document useful (0 votes)
3 views35 pages

Java Part2

The document discusses the concepts of objects and classes in programming, highlighting their properties, behaviors, and how they interact within a program. It explains the significance of variables, methods, and constructors in creating and managing objects, as well as the differences between static and non-static members. Additionally, it covers memory allocation for object instances and the execution process of class methods.

Uploaded by

a4118099
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
3 views35 pages

Java Part2

The document discusses the concepts of objects and classes in programming, highlighting their properties, behaviors, and how they interact within a program. It explains the significance of variables, methods, and constructors in creating and managing objects, as well as the differences between static and non-static members. Additionally, it covers memory allocation for object instances and the execution process of class methods.

Uploaded by

a4118099
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
> ~ feestiee 4 a ~ a3 febjame 3 ce \ - Object _a claes! — sO oS wand Class: - 4 Object |scoatonce | ent - 3 ~ngiigs which is present in real world ard hoving prev 3 eristence jy Keown OF object eam per books. rl eper sores ere SA poof object 6 >in this, world we have > Every obfect> i) bowing here own peperies ond behoviowrs ey preyen? pehavion’s poyer@ Behaviours nome eotind ats prond Coding watching roe ae lee, ro ree pr oy er on Coe ET rey Object joret 19 jer object 6 a Rete 6S block + memory? which is User 40 sore cHre multiple Variables aaaress and mourtiple methods, Va iable Vario ble Variable bom ECTS opTESTs — vetented by the TVariable nol p 4 In yavou proger ties oh She objects ave rep meshods - VbLELLEE LE REELED LELLE EGE Clase Pen { 7 rye [vaniatier) ae v ps vm(s03) fer@refoxert “ cr pl C*stort Dy, Nose heat pre a5 Majer So new Pen?” s on pinCree cr Creation Oo Creare) eye ca Oe, wae Creat 00! — ee yet oe domed ott sy ee! S$ int ry, alae pint on Ont } opto (vent) arr wits eh dees ; owt vor ese OMT dane eu chase gore! Jove. we pew So, Jove ate dev Called a DTI we con create & bhue ea re pep wor execution pel “main class’ eo pagammer, ame sho! addes> heen Vananlie ef 40 create & Clase block and wae ehasd create sp 9 Objet cto ine Keoad which 16 ote this oto ons 8 e blue pent of pediess nated utd store the coe Clase clecstleme q pens ewe recta) of prsiring He oj TS oro store Objee address 26 shout! Ry Seba: — _ (pew Cleator (CF object vefereme Voriatble [non primitive Voviable J! pew CloaNere ' T ; Sa4 variane wbfeh fs wed ro store “objec cheeess” 15 Known 28 clove object veferense wovehle Zuo con Creare cipet weber eer nem ieee Tact NpoT oor, Negord coxa calieg 4 new! — Colas name) “heap oreo! E? er cos Od Gree snes #5 4 Keyed wowich wed we Create on objec insta at > perk A cejeas 16 toc, enue odes rt ayo Tee erd, reo i the Obed oddvess ectiess ofr, Cr: y “eg pee a0 5 ax toons) ra) sy class BookDriver{ prego — ps vmCs act) . Class ateimbers (Members of members which we an Cr the class block i6 troup Closs Book { To . ies K brs upepele) emotes 2 y BoOK ba ENED Book <5, hss Cheeclame so oC mds t. 4) variables % oneinods J caf m of S:0: plo Che); S-o-pln Chyz=be)s Aft) wnigvaligey 1%) conenuctor manne } Te q ee colass embers clon—stotic members i Chats Shed Diver [ PsvmCsat3) gegen “ Class Studect 4 ‘ f apap en iene Seat ome sen: J exhavious [J Shelnt $3 =reosbderti etic ware eee ee a ee ame So: ple cerns Sr 3y toric Ini bializer pei stane fntbfaliger so: ple C54 20H); fe Sm ay Contractor AD ates EE eee oes omen con goatee! are Spe sees eee anqova, ore obgct Ca” mast ipe abject referesie Oma yam . jaa pempers cnn ve ctectaved with he help of star's >but, One seference variabe is fot poring po mul Hple objects = 4 ee is a keyword ard modifier hich ts vord 42 enticed = 2 rrembers _ A when The proper Het lord behaviours of the object is Gmmen fe av tnbervian Question: — wpudhat is obpt and cles? by Ming sce ead bet in prot C1 Te ea ene gramie. mente 93 #1000 10 ciate Obpat* y) Fxyfain ean Keyword? ) wna is myer pene variatie | Been Vevibe [py ’ nuit igi enyect refer variable the objects static Variable! — cing oriabie eh fe creclaved trfee claes place 450g statte Ce le static voriable vequord 18 Frown a zy de Demo t jae tnt as Aenvle enh 41m Sova, for at! statfe vartavies comptier fs fort rey & Ctefamt value 4 efout vale fo tt foized toed em detente 7 “ae I “mp °°" oles pater ype pepaurt value Dither < ee “a 2) Clase Name C+] a _ “= 3) abject rehevence variable ca ee) e “me so 3 ctor urfode ches & teowen “a” { ‘p) clase false “7 Stoic int OF rivrer J pall “7 pootic static void views) thods 4 t sy sraric Methods 4 aro aC "ots cass state membeu’>i a a ee oo Se ts cs as steric method pallid public oratie void main Ching angst 3) eq cee Oemo : Noivectty ofp: © i potu class static mete pustte stotie void mc > s-0% pad: ° t viewo); pata class Static meme 1 avarice retbod Metaceciame Bru class static Mar ; 8 o-plnCnole. a): obs. viewed, Static wid me ) { " Obj teh variable petatic mettod : Dolu di = new poluc?s y S040 Cadiad: iv Ad. viewe 5 i y XI a ES tt piferent> clase: — > classclome [J 2) Object mfoence variable [+3 clecs tas class Rani loss palm t ( lacs Boni gvavie double @ panic aovie 10d male ) site srosic void print © t rovic seid print fi { sept ) ) Jor) veh variable tala yisrew Rajot vu Ys Netascclame 6.0°4h Craja2)5 crf classé ys Roja print 95 pints Sopot yupriar > X y ve used 40 inibiolige *he shartc vorianie Gnttializey ne storie qe cedared fhside the class Piece 4 re come is Foun ot single cing tate aliing Me volue fo 1 ‘se af] Re ogo neste inibiali3er ) cuit tine shasfe fottialiger: — chny black which 15 dedared tnside class qedared tnoide clacs buck y wing only Marte Heywood Coustnout- ot ; ord Covtnouk: err Components) 4 Rraam 9x Mattiting stan Inihialiger 4 TF is lio town ar static Hat Cor) amy rrot Ege clay tet { « siatic fnatce a se auneraricaly executed Bering t tap pre, all jooding proce tt Coefove ae ctatic dt less AT h class is having muttiple etarie 40 bottom in sequential order jovac Filegewe Jove v Hare — Execution compilarien jpvo file * v class leading procesé wd Wa cally main) boPbbbbananaeeennania a , Ezaropl class af stavie { So pln(‘static intiiatizer "5 y state { F statle higer-1 soln Co steric Iwtiele =? > ganic tntialiaer-2 3 stale nS de el cain stoned main Ended eo pln (Main sartedDs soft (Main Ended"); ae-3"), members: — Clas one soa 4.2» fore, an the clatic memben alacating Ihe matory insice claus bece and chs block ig pttent- incide class atic area Fowap cloubict rane is Some name os cleutlone AAI ery claw ony are cau bee 6 ff created ssame_class class Oemo f atic int 2% Grate dene 65S public ctotie void mic? ¢ ¥ Gs of vO incabt Steen nen alee he ‘i a n ¥ a & > Class Teck t Claus Samp | { static void mic? ps vm(e ayy eS { i Static Shing Iistatic mero soft Cres), | Sots 3! yam: Lexa } cheb cone! for stable membersim 1 ose quarts weners ave cleared Wy osiny TONE 0 tie wy omn the eyovic wnembers ate anecer | 4 which is recent in class storie “Oe? ger ave automatically Ye esecured S674 nn me erate Toft clace wading process seiple sto" Srp cess is ter] reottpt ge bortem in Sev > static members can bf eceeseed ith’ + Coneetty clascNeme) eerie moment = ot at of the onyeer is commen fer ai je faretoliger att te Te! Nigers envial oe are executed 4°P ave one Souner ate prpertice and behatl cbjecrs then we cbould use cratic wnember progres clase static Member® t lev spatic For void vier > public stat lon - ckatic members! — Sy arene members con we creciovad ntOeT using, static begs toner he properties and behaviow's of the objeer is for al) “the, cbjpers “tie Coe could use nen 6tatie i" Aicceccatiliny of cimzstotic Slemvers ' a. mermners over creation eject 4 ts mardaton Sina, 40 actens name 3 Then, we can access woth He MIP of ot reherence vanabie ember’ I) Some class Dalon— static endade ches black without ung sorte 2 cijeente elees mae Jory vous ebich i mer] arie vorioble 0) come ess: Veged is HON OS EM Hed eith cefowit values eae a onda f boolean o Wnts t public void pant? eee WF BSF emeatatic vores Pe estore etal au : eqorie word ain vince at) peptic eis ae © ota dt anew belts 7 So-pln Cavads 5 Pie pine oo hed aihrehaore r or etiygerer cae eleo 3) vencsratic ened” Sh mote ecee . Din came close ond STE clace abjers creating. |S df Known SD ecsees pemcstaric memeelt Hine a meitod unfon is dedared ofithout using static Keuors wetted mandatory ayosenr storie Witieliaer’— ymeialige the pepe as non-sratic Eq ctose ® 8 t arr is used 7° do pak ee there eve “FOO TAPES Cans y single Hine pene steric initiolizer ay enusti tine fens EFAS relider Noid viewe? single Mine pons etstie el en, ceclored fnguie the class wrthes he value in The Same t , _ stog voriable ooh fp using eval : 4 wep ond Single ine vane otic int ts trou Wjer ols TA ee > EG — ¥ © % Qen- static 2) caurtt Ne " freeing Thalae the class ne pen-static moot using =94 Tortioliger which Ts cectou : tem staric block Cor) ‘Brerymeus black ATE le also ENCED os Eqim class rest 4 i 4 laense y { | Mea iner, | ? } +t IwSpve on the loadiny* procrsc Hovjecr wonsiny Tap we nen steric BBers ore executed during cbect= ocece! ie TatINY time daring “ovjga Ceation” cuente wuntiple ebjtel#: UNI ple time Cbject looting procese te happened. jotrioliaes it rs is having euniple nem-sraste AI ewes erecured” In * cequenriol order” ness & a= é pio Crmenaereric ts ger 1°95 ; goutialiger-2 95 é cater storie torrid seth y psvecs att) { sorte C*m6"); Lizer- 3°95 so: pln C+ Nop- si6t¢ } 5 a > Memory aitacation for nen- static Members! — PN the nen 6: members are alocatty the enemery Side objects which is Recent inside the beep ores ween Heep Example program; — ee cei aiceeme) fe iat pantie word IE? t Inem Ye cranie void main(s of) rate a © oie averse TOE) Ay cee emo C5 J 3 pa ee 26\"reb.2026 TH constudor:— yeorstrucior 10 a epecial non-stabic member cobich %5 used 10 Load AM the nen-static members Fram Class nto object Pasa pepemnr coraicior 15 also used to object (Gay * ams < Sane a object spe access fpeahie> Conspuctor sf pr 5 Rules +0 a (tome CLeeaa| oop) Zo voptionel or) aft nasod object insmacton[ eek of tnetnaction a Constructor! crete VW Constructor must be Ceote tnsicle “Glebal -trea* BD Concructor ctocsnot have any “modifier and vetun type * BCensmuctor nome musk be Same as “classclame ” Cincledin convention] Closs Test class Demo lows few os t ‘ i ead static pone > vod wok’ > \ { INS ba ) 5 \ ' Cere) CoE) a) Bisa era avert = a we a fone! bee Cemetary tne ams forvioliae properties of d as ze “alig the Conchuctor Spras:— ew | ClacsName C 9; J wd eosnucy Calling stotement class Tee ) Test) { tlLor 3-0 pln C*consnuctor ” ): y publtc static void main Ceming aged i °. ploCeMain stoned"); aang eet t= neo TeetO)s beer oe enew Tesh) ‘orsionrg ann soqlnC*Main Ended"): } J Default Constructor: — Compiler ts acting “aafautt- conan 3, peyommen, is created any Censmacter, “then ‘insert clefewtt conchuctor Before com gfiatfon Clos Dero Nt Commies } Daring compl ion Cova filesame adi Censruoros PEPE pregearmer lepine consirccrer ) in ova, if popemmer is oot created ory Cowmactor. dusty SEU cee ee TIP pros constructor te alto executed PY be peg omer TBurthe canshuctor Con ve Called Only dering object cirarion [Ho- “7 conshucror J se jain starred Consrrctor consmuctor omin ended compl Compiler ell nee stfter Compilation ype nefoust” torch! chas Tet t {| pefoutr constructor I vm(s att) d diet Wearing process noreh aac StepL-seodyatt the tensive vores ih defout vale Toto the jects aeer tae EO esr 0s I) casting defpoulr Conchucrer: i. } cryet of conshuctors— conshuctor step tisoadag alate tomceverie named iv0 Vs eojeer rnin Sep Bim Executing a the nen _avavie S6trialiger rere fe 2 Mor Hl [ecquenrial ovcter] “A once, all the San-sbahie fs saliyrs me cnecated,, jeer toaing process ts Completed fe Simple fob a5 oo 1 oo eeror pryomney acting conenucror eae -aogonent- Conshuetor . rometeriged Conshuctor ma buble b= 56 Sompie r [ hoz sro pln(esmuctor”); $ povlic void prec xf 4 { [ so plo(emensr"); a } Consmucr ov ctor iagement— Consmuctor — ar conenuctor which does not have Forel Orguerents is Frowo os alo~ Argument Coneracrer poremereriaed cenetucters— comersr is enown os Cenamucror earach i having sonal ooguments ny ror porormererized cereructor program for poramereriaed claw bewot — , Cink a ,clouble 6) pubic evaric void main CS 69) ree { Censhuctor somple gy= neo Semple C % Sample 2° 2 Sample > } enain > Sarepee jor > 06P eee members: — ronclusion for pon~ static claved without using static regwoerd Wen stabic members are members are soe a the memories insite the r” which is execared ers ove automaticaly IP tl the non-static during object teeing process ae tye oon-ctaric foi tioliger > If class to hei] execured in Sequential OFder / , maners TObYeck Creation is mandatory” 5p TO Access rep stene MS s “oby 7 ove ‘multiple Copies” Gy Nen-cratic Tempers OF HP r > when the pepe for ost abjgers then ce choutd use com statie embers Oiffernce setween ana ties and behavicus of on object” is atifferenk” non- static members static pon-ebatic Members jocating The an as one so Cea toside the “class tact’ which ig in “C&A Ph the watic ToMalizers ave antoraticaly tng Coss Leads os RanRne RRR AAR AR #8 [Ep clone v« Posing mwtripe nen-etati get erected in spericlode penashavie wanes ate AEEEE ONY totic member ave Hccemed veavioe Colne et wopject Creation pyec eveatien” ore mamipe apa” Laneogh Fe gait Taw Aas dine pend) si were ! : Dee cement fo elark vremea vremery Patence, 4 we wedity his obbecred for MIE: nen-sratic memvers ove mutifie SY etloce ting the tence, if we objec 4 1s wok obbected for Nov-static Alafe static members are Siqle Copy becouse It 14 allocaring the de clase block re apalie memners iim the netp a Hoa, Second object becouse itis ingide object memory moaity the pen sto onather object [rurripie Copies] cls. Tom { ink ay ps vic) 4 vTorn ty =neso Tome Ds vom #34 he TOU: Hh = 50, “cratic [ singe ery) close ery £ gratic 9A) pe ven ‘ seoy jreree geo sem Jos O08 SHY Sheaesn: So marcn yer ~ tes and beraviours of an oWeCL is common for all Setatte mempe objects then we should use Dhen the progenies and enaviour + caper is diffecot for ai! TS static, Context The awa which ts cata Tetefatizy fs Krown os static Co 4p static method ond rout i Nie crate mre om + public efatic veid mre ) Static ‘atie me [' 7] 2a) Coan Non- static’ Content '— The area which t¢ belongs 4° om-star effalizer and Censtrucr it Enawe OS ie rer, mattictine omn-aavie Somn- static content nen-sfatic memben /, meennnanay = ii Pr in Qlen- static Context ch t 3 cc B public vid mic) Bc > Ns-¢ i 3 D301 ches Newel] Mec easabiitty ifferent” Context wvecty non as members Insise sae face of cratic ord popes ove voriowe praric center Now-static conten Nan cab Canest Cojjent dbs) | Cseme class) 1 wanef BO [eben the a onv thoev woo | 7 - stot \oRv {onv 8) © fd march) 2094 Ss ng, pestis of object mane 1 non — In tte ony 2 Object telerence Variable: — . em pos t having Some volues wi alige, [st] Dobject reference Variable 3 Porometened Const Non- static init fal tafe folider [si expe vie gle tine Witiatiger] ae SmN _ a Let us Concicer So “a a > lacs pen class PenDrivey a { f , t __ | Shing rand = "sontcor”s Ps ¥MCs 03) “= pupiic void printBookDetouis¢ ) —_ . seme: ; a a E: Neor eee { we Pen pis new pene >; a per pase fence 2; nor Pen pas new pened; t pnsm police 5-0: pin (Brand! 4 brand); Seopin Ctpice:"+ pices sopn (*------ 2 a pint teopel alot 3 eles Class Book Driver { s vmcs att) t santoov i “grand? sanrecy price 10-0 Brand: sooree’ aie! pie 00 = > & re NOTE :— fue Poftfatize Variable, if sequined matte %) pevosnerter id Conshuctor’— lore Somp t jor a; Courle ©) Sompe Cink ow, double») tier Mot ans be; i) pel { < void pant C? go pte Coe '49: s opts (“be"+ >): Sogn Gre 4 r 7% $ giz new Sommple ( Sony Ober reference yy FTN ee kayoad wonich te obonge poucing covert” cljsct oldvs *wreM we hove ngn-stari¢ Voriople and local voriove with the some nome, tnsice local arte Ice variable ts how aaa vowanle, we shoud use cratic + In-tnis cace 10 acéees 9on- renee t Pps ve (sect) “ahy keyuod coe ee : so Sample (50,895 “hte” can be used ony Snide e she 0nd San : ‘i> class Deena / Somple $2" “a Mose Dy ane > se print OF 7 i yl eee ee j “7 Hey soqtn Chica); 1110 toe 3 Hing ogi 3) . bree bie tate void an (sting orf sie: ae : emo c > (oo , ee U one aree? ° 8 — ab view 8 ve ia clos Jesendives Se § peor php this paine= name? pp op = pe pi \ be heh op object" Chas watch { ching bord ee sting com ete! uborch ving bend , Wt re shinycoous im site) word = rod’ peer Pe? ake cour = colONT ak | BRET SBEY s ; / quote void pit torch details.) ‘ so pe (bond! + trond)’, soln Cprice:* so ple Co comer + pred ry cow scope Ctsider + SiR} eo fth («= --- b 3 olpi- Bord + T2° sw00 --- 3 proce 5 | wo pre Caloar = 904 side 730 psy mS V9) declove ovr properties ard ‘ritvalige wit “nr pink att the cejails of watch clas: Watch Diver y nie rae CsTHan® , 00% blue ,10); tench joise *, WOOO» cw Constasctor One ining The process ofr ceoring mustipe oo Forel orerrents, is eran 0 Rules to change 10 Lome! iaguments Neege 30 0 Founal ongement® 2) change 39 clateryre of Formal O" ments >) charge in cxder | sequence af -Fornel ogres EK -_ a Somple. eg puctors sCenepuctor overtooctng inger rome dass but chorgtn er Sample >? {hor in (“conshactor ~3.') Conshuctoy ~ > { teor Conshuctor - 3 -[Link] (“enenwen 2! consnector — 4 y Cmghucor ample Cetoume =) . eneracr Detocig {noe Beng aie Cm eof te lace is bavey pe so mute ue Can creare an obfes son cman 3°7" Fon his Here. peyonnny * bong wore DempleC inka double &) £ jor evening fo create 1P ovjects Sorte (Ctcensrecror 0), sa hewo clas To as Cevuple b, its d aaa d ‘pete fMeor 3 Y = 50 gence Consrucers™- 6) ; pet ; pars diene ene 695 3 t ow xe belante ye yenen Terre cadayen Tah teeta pacng MP 0 an shot in y; clas “angle, \y gape (57 MD SamPe G RP ae onother constructor % qneruern ‘neiae onorner Camemaey aem= © ©,, o am oF oR EE Gr ~ mY Age { : FB etc ots fn me 7 tole. t The process of ore Coructor ts cally auntie ep fe vm Cs td Keen 25 conrructerotefnieg co) ae Shident (Shin come ghicent si nee Stictor (“Por sh ba yee Ge Ce 7 ¢ gh print Shiceor Peta “ibis. pore = HEF } Saaent (Stn vameienet) £ Gude St-enew Shidert uretb*, 10) $2. prmwPade jails C chalet 45> TO -thed 53 pink Shadeo tDetaiisC> bis: rome = nares “Kis. sid = sid? 7 aqotens thts Comme) 5 C felt eraen os en cmucor ced Constmctor 4. Calling _5 consreucror + craved 10 100 SOs “¥ concreuctor chefnfng Cor) calling etatement some cvs] 3 ; ar sree come 78 sidaank eg) 3 5 a oer enh oreo ; abies pomne = FOES 2 a_i mat! Super CeO)! Caifherentr elt ane ote sid; = : a a ke eye qt : SMS ts allng weate can anarrer conan 4 ci ee a» Ctbis" qreremert” 19 vet ea aor ved pint Stents eye FS ‘ote te polar hme a , ese : te present” cameron {it coteume? cleme | See SMM? ete agenesis weet a Loo pant nome 2+ name) ae haa g =: 4 satis cling soterenh con be used t eer . 2 clame « Mukesh _ - Conshuctor » it Cid 1-0) Seer ias reves L copte Ctoid s Srsidi QTE | ~ {ior so WoC") 3 Conarauctor Overtoading i€ peme Cink 2) b. a aco? vemol 76) i aaa Gerald a £ soph Cree"; eo po Cone") s opie (* cqpa? + ap): * cenmpie tiene pyrronphern Sor ° ; 3 demo ¢ e ) eofle Ce - -- - % ioe . J sbisCs00) > woain¢ 3 34 Cony > a so pin (150 D5 RJ i \ ~ Y emo (aesble 9) > f cor go plo (tee # a FAL 25 autowartaty vewoved when oe 1 NY tn! po a Core instde a % factor WE CaO A Hence, if class te hovieg ae ay statement” ony hcthe help of is oot tnel consimuctor staternent ” +I joo, constructor vecur sion centages of consrucror chS! stax cecte re usopt ty Pa > a Empire Shing re int emp crue soley + cree core) cthts- rome = Fame B e Cig ome, 20t ary'd) Tite Cones shies emp = orp tot emprd- dove Salory) athis- solory> solory ; vO Y apie void prt Employ eto! { “t Came [= eatt) ‘ (1 ntame 24 name) sof!” 3 if Cengid 1-0) ae : 60 poCrempros” 4empia)s if Coben) [=00) plnC log * gsalory )* Lopate pee ece ee 3 y loss mpegs! & ae toric void rain ($ act § ce ooo epg Coto 11, 400000); eel empl Emp empeie e-prnk ery! tx pint Enpoype Ped 5: po Epa Oia Pea exinpeCPt wes es = nen empiyee (eho % os loyee Deral | ie 5 ‘lame + Sabana emrip to! solary * wave 0 Name | pee empl + tor i Hawes Bhavana bree 2) class Lapto { Lefton Shing bond {nt rom veptep (shiny biont) i ] J Lapteg (Shing bord: Sting caus) q “ikls-brond = bend ; anc Coord); bis colour = Colwrs 5 — laptop Csting trond, Shing Colour, double pice, i0t rem) { 4hic (brand, Colour, ri » sshig- rare TOMS ; > poe void prot legrep al C { if Cbrend t= 00) t ‘6 opteC* Bren ot bred); 3 i Cenoee 270" we-pln C colour * yectour); 2 0-0) eye! iy Cpiee $= Cn ceyues apices (+ pie: +pnce ds y go: f!° Ee eee SBN ilove “a t a ; cofoC tere 110%)? “me eho --"% a } “Ee J “7 yw JoptopPriver = pose erotic void rain Cs etd) ae 8 voy Ne ven OTT Conppe TersBte”: 45800 2 3); a — Ee = caprep P30 mee pry Creenere” “44 “= vaptp Ie 0 wapey Cater"), “ar pers “a ot taprop Det C5 BS peer p oer ~ s 5 _aipi— prone: “Tye “a corr + Nonptle pate + astco: O tom: 50 . 7 pond seth cour: Blot pre + 3sn00°0 ~ : ia qenovd 7 Gey bh. - AC e& choprer 6 1 TT Soreeface con Conshuct 7. frycensructor is 0 Conshucter “hot ceotes 4 ree object PY Copying 0 AT dasa ow 09 564 package coms class Monte TS yockoge: — * protege %6 0 colection of classes ond foctage means a ce pele af the some Claes onjest trond, Sng muctel, dounle price) Movile (Sri t 0 Tes oh packages: — D predefined pactoge 2) programmer cece portage J+ redefine package’ — / precepioe ort too collection F re Forerfoces y copy co 4 Mobile (movie of this: brand =tm-bronel 5 _ tis model =n Mode this price orm priced y nem purife void print Mobite Der f 5.6 ple (hands sbrond); 5-0 plo Chose" me So fln Ciprice "4p" emucror fine choses ond pectbine rp tova 1 KOEED OS tng. ppevoge atten alveosly created % ‘pv pre-e ine oe eoplo cee y wasnt - cbs pier { PT nts te ceted yore public grarte void main Sing sc1) toy prt oe t peo Movile Ct Ephone ornar " ,'50000-0) 5 eye" rire Mobile rol ant pring Mobile Det ©; rmae pew Mobile Cri), pare Motie Mopile mae new Me 4 md Pint mobleped 7 Mobi (my; ee PPPRRARERE AMMA AMMAR RERRaBD! Gracioe a pepeeen ehice feese z BP nccess specifiers: — rer om spf usd 4° gecity the aces] ond “the members Y we yecipinn om be used eohfle ceeloving > wetted %) conshuctor Ti) clas variobles (steric, iyo of whet pepe New Jrot for tocal variable ii 1) pubic Plzad x protected For berier roirtante of Cae fang ro, access enuTly OE chould use “7 > oon ceca lever} cucraed prapommer clefine eee ert » private eae has woe con use oniy parle and cepomtt Actes speotiens sor “the Bul, For the nes! al the -necers WfeC sinner clas” we Can He at quabitied ClaucNore:— Clas vel ic ETo@n as folly quolified(lassName, whome om the poenye ed close en jor He s ! me cee Faen [Link]: Sennen a Clete insid. ‘stance a Shing jora lary: Shing ae sine procees +f creating enn os nested cloe® i clacs Ovter o:! Onn class Toney chs | oe r) y bier defo matty? ” Je tne oncther ier 12" march 026 Packaae p paccog V ne cles ¢ : f i rei Dithevent-cleus Different: Jey" private Tot v5 x Sefer . “ ‘ Ay venpark stot y prtetef wv v veer veleinihp a a ce posite vv ea A iyompe at t. . ae ger eine A ingot statement /— \ } ‘ys = eee Vy = Bs em myo stem fmyor stetement ts used to Mpert the classes and Toterface Ferm one pactage Tove oncther pocesge s 7 oul naka public > povected > depos > Py ‘ pece ceesei Bitty more ~rcce £5 tess security yer Fully tualified ChasNome 5 moe Secu hy v lace enucr be public’ access specifier ere S0UCe cute! , SE Cifeenr eles Ohne pactage > potected chit embers oe ce wie “the togrr aime, 36-8 relationship bath ave mandatory MP i5 java, we can also cieate melripic cwe® : 1s Mordor cot <_ file Csre) 7 as “Dinerclass “PIN this 4inne Source file La ewes enich Peviny ¢ Acces Specipien "omy tor FOC fablte Acces qqecigier ip 0C.0P on The Giffeence omeng the public ond ckhautt clas %s om Ce omerg the i eee ee mein erred sthe fmnport statement is ating cen ue ule ONY the " I | sin anis cose toe can use “pl we camo ute “fe 1 class! z public loss sy aefouit Class Tre impor ment io Th we ue impor Hate { sa oo CTE te raise “pattie! eee yf PRRRRRRRBA a 7 Chapter— + G Playing eotth Objecto:— Exempte— laa | “Thee are +000 “we Package Plsing -woith_onjec > possing je Shem celles smertod 78 called method AUR ie I % peony caja fon cated vocnnet 78 aN rete. [Foci = _ Pay shat we “K paseis bject from caller metted 12. called meshed -— soar, , passing Ce ) Class GeeDe "POT a i semC Sing ome, tot age) { -— Ivor } “thts: nome = Darne 7 “_ this agp mage: paptte cravie void view (test +) “= ; y { te oO “= pubite class Personen S-0-plo C+); ona EC] “_ { y w Se pene wed pone (person) 21a F ee 043 pubifc stetic void mains at) “= { store the pet objpa tras lame ; Balttha i AL) Se ie von set); tep. a pln C*-ge aa Ts eetuins com op y 0: plo Ct--- "): View (new 126) cect me a puotie staic void main C6 003 ) a one ¢ me temo ~ 8 ee view Or) P co penton (Rachinhas 253 ge y feson_ P2 = neo peren C"dhanu", # “T- - CoGautham”, + a print CP) q ee WAT P 10 print ~the same salon of 400 emploges Packege plan eatin onets class Employee { highest of, he Engle wore saving sting name i fob emprd + doube Sa Empieyse [Link] t any EMPTD, double sal ) name = name + EMpiD= EMPTD; Sal = sal) y public closs EmpeycePriver ‘ void highest Sal Cope! venpiopes ) sox! ved) pobite sraric t avsal th Coupes uz € (sevenome + ; nei ete if (fer ven BEER? t 3 eve E co gnCtea’ ): s + satay % wages "5 . iis ighest g-o- ft (‘ex + ame * gatory 19 maRRARRma gga p & public static void main CSring at 3) { tempuyee etre Fgh anya”, 101, noo00:0) Feopoge® ee rew E inplogee ¢ sarge", tor, Goan 0); ", 103, 40000-0);, Empoye o> 6 e mpage Coping bignest sal Cet. e2)3 } oe Nawya catary ts hignes™ the [3 "Eacory mer bod A methed hich Ts use Object acidvess foro the 4-10 create “the ebjees and retaroing “Caller method’ %s KRowr as the “Posters meted” always Factory method must be “sbabic method ” public store Gemd) prec) t fe oe eee eer Oe sym ce atid eo {| So pls Cprintcr) $0 pln Cprinr ©>). Qemd > perkors “nel 0: pin Cn); Hon? so plnCme* > 3 > ractery mervod meted % eon- pamte ve mae 2s Created when ~tte Data *47¢ on OKa ME PPernPPmnnnnananannsenegeagh \F g z Te Returtg tne cbfech fem Gall meting Sato bite class shoe pal t Shing brord dale prices shoe C sting bord, douse pice) ‘ : thie: trond brand ite hos ie } pobitc void print Shee Derails ce) t S-o:plo CB brond "+ brand) s-o-pie (+ pices" 4+ price ates") yi aa ‘ Arn papiie class shoo Driver Kage oy t ee Ineocrory method / ae shoe create Objee( Shing brand, deusle price public srakic t ghee => new Shee coed, pie); oes jeran Ss brand ¢ purna price + so00-0 es y ponte stoti cehae 617 @Feate Object C* heme so-plnCst): st print Shoe petaits (5 ghoe S2~ CreateObject ("Nite *, 9600.0) 81 print shoe Oealls (95 ¥ c wid main Cs aC2)E — ponds tre *, 2000-0) prite: 2500-085 ising Oynome Sopa ae Soper spracunl b Seeman paste class shoe Deer { v eos (oops [objet Gren ted peyerrng Stucta a oops #5 a “design principe” means one wey of wriring rho the cocte ne vent word ofp lle "y a CheateCrjet > Sn this priseipe we con easily reper rh t REREBSD RRR AR RRAR —_ “clos” ond et?” Inside software word sing 4 man sc2 2 Scone Stem ins eee oeeetlc vs a seople Cs enter ronal): hee ove “Eau” oops PHP Stang bonds seiner” Ip encapsslarien : » 2) \nheri bance 50 plo(* enter pve’?! : dene paces se-nertDome cds 3) geet ser ae > ) *D caerecrim Aarorch 2026 chee s+ new Shee Chron. FRET” oe eon Prockan “_ =— aoe fog Data Members and Member Freections ; “Te posse of ncn OD ey vee > Foo. sfoge unl called as class fs known as Eencopeslanien AAR erp mie copsile ps t ghee six create object 6 objec Chass veo yas Dri members ee : MO Members: Fanhon tee 2000-0 : Sa aoe om cue bed ai — penne S # Data Mate fe -ite —Rtvartoe Encapelation LASt-0 Tn the data ond povfering EEE puvole tnt age: pablte fore gertye i ry sedan og } tg Meck 4 fi : worth te Rp of help methods js Known as. « wate Shing nome : eer protic Shing { tetarn ame’ y nae MF Jao peo, we can weantct the eck” acceesibiliy of cae walt whe hep of “phete* ord erinen ux veshict “the ctitech #eces: Saati Aa! herpes meboass Setters Method : — wate Noliabies fo uced 10 stove “the ily of the vortebies, 10 sccess dota too pr fe required Eevter's method Spro store “the clara Fis TO fetch the cate eer malads — % Gerter's ,mettod > Setterts oetbod ore: J the relarntyye: should he must & ogg" bor bere we shore HE dave. te chowd pe poromererised method y Syovens— ovat nome) pubite word cavortable Nome ( catatyre f RAARaR eRe A gg gBR In Jova, both the merhads must pe Pop staré Abts, vartable Nome = VariableName 5 vote A Getter's ethed t Gerter's reeitoa fs used 40 y Eglin pitate forage: epi phete re wold cetfge Ciot-age ) la void set name (Shiny name) “perch the anata” ram he pr varfa be. Syorar— public vorfoote DosaType t apt Wiasinane Ge) bis aye = oe: canis name = 90m 5 return variablenome sae = qa) Gm wo & ) cq) food an] Wie . y \ read on | pe tmport fore Sennen, clase pervert portic piste fy Tor passwerd = 16187 Gerter's ret hod Cis’) Eaampe poyen fo Donating += e ile Nos 19123145925 Hew Serono: Foeege encapsulation; 1 Jowa. ubil sCanner, public clase Phare t re write ony te douvle balance = Coo00-0, IIMsv opt pin = FFAs i 1qPmared, 2026 Getter's method pabite long get Balance > clase Driver { public star Céving angst 1) cut pel Geanner sc= new Slonner i void main { Cegstem in): 6:0: plo (* Enter vp! pio: fot plo = se-nestTrrc > if C pin = = opi pin) { poosn lene persone J; So plo(ph get Mobilenci) public tong gateunene ¢ { Scanner Coster i); y retare balance 5 Scones sco new Sconnes (hs 5 } : wr pwr se pest Tore) gus iH Cw = password? sword leturn 105 © an ote pose ; y usar else f © Cor chave the rane d ; t ' etwn 0 pre jotend (ois Cres word ) ansiasse Y ree deen Sleps 10 aeate _fowo ban loss) — Sep class rust be ‘punite” neces cpeabier vote’ BCC Specifics Sein An ane popeics rover Pe + ovcrer ve optioned porite class Driver etore void main Cv angst J) steyai~ Conc stepa= hone = pew phorepe C >) Adie eres pct deumie ne pe gettalance % ey ft vate Vanoble eaters mnethed equa bean Class! Examge for Sov Packaye ercapenloien 1 Jove bean cles posite claw frecucle d if Co t= 40) { 6.0 ple Cawibbee balene ? else t } } II Gerter's and serter's for Getter's method puvite Shing gerNomec t 3 I) setter's methed pubite word get Narne sh name ) { 44°RS")5 RRR gga prhote string some; s-0: plo C* tovalid pin”) prvote dovnie pitee; Shing name age Enter pin oumber yet name} tes inetd pi? Enter pin mumbey this: name = ame + 3 I] Gerter's and getter's for double pre 452) availabe belane 1s: 60000.0 FS BIE ! Fe excopuation ood Dasa Hafng bese Example 11 Getker's reer bod pubre double ger Pive” > { rerun pies J PPP rnmeeeee N setter's mertod pubite word Set Price C double pce? { Ve Cprice 79? { cas pice PCE } Movite evsef ps ae pecameld paced: ~ valid pice 5 Mobile O° [aehoutt value] “{ partic static void main Cs att) public class fiectuct new proctuck (>) me C*Mosite"); yi ce C*4000.0, cower? pret pice (~ #00002; weap: 5 so: pln Cot gerNomec 20: so pio Cp gr fncecrd: 3 j ample: 3. coefle package Copulation, nges om Pee eee ertec's and gerter's method or Powe VV Gerter's met bod ponte doable gefetce¢ > { vetwo double) pte 5 Il certer's merhed obite veld settee C deobe pie) t this prices pte seateris and serter’s wwerbod for brand. WI Gerter's meshed unite Shing aetrek > { y I) serter's merbod puslic void cxrBrand CString brand ) t retrarn brand), Cbrandt= pall) rite public class montle t canis: brand + beard > t pirate goable pte? } ‘Wis: ba priate Shing brond else vate ; Eggo Ct mvalid iy private sting. cau; 5.0: plo Ct mall ‘ a 5 : I Gevtecs: merred pabite Sing tions d t 5 I) serter' votd setColour Ching Colour ) tetaw Coloar 5 ts mer bod. pubic { sthie. Colour = Colours punite class Driver{ pusite arotie wid ain Cs a) t Mobile more new Mobtle C > mm} set price €50000: 0); ror set Berd (samsung); mls SetColou C*raverdar "D5 So pe Cont. qertrice os 5-0: pllog mnr- get Brad (9); 5-0 pInCms get (olour)5, [TF clossitication of variables: — yn 25M march nore toca! variable static variable Hon-staric orion printie vecal vob waidde 1) pinmitive oem static itive ghovic oriole 2) Nen-primitie RAE ise vocal vor >) len 2) om -pri neuseaet stotic vanoble fechas com puslic ais emo t pes 0 static %r P steric demo ysl] p-sv M7 ea) tov ons pansy fo nat demo 5) Np-NSY panic stare void sain (6 03) { ier asno. I p-l¥ fhs0 new Demo 3: e-LY Derno a= FRPRRnMMRnRRAeneeneieeennnnny, tepre sen hay 0. relavionship iy java: — Crate poco” fe of oper tebevenee gH A von Nside Eryencting object Gn veal world [E Retoafooship The Connection bet ny seen ~1100 (or) more Objects Ts Kun 06 8 Eyl Gar basa Erytne oe sip-isw - ities - @ ay is-a Pin Cor eet Eryre oe — 5 EGE Bag hasno Book i: or Object fe Known as cre cops ts Hp” 1° another Ob} - pee ‘Hos-a_relationsh ar oes, wp-riev pleat ome . Algia tom ai" ermch p08 object , “ . ojo ame ecm game. easing! + onjects | instance | Eokry Car tos-o ensive T bopey asa bottey ‘l £9 mobi vaso sitmCard + properries| seninores| erates fas book nn Rai + Merbad | cunction object” se herent Variables crackles store “the gr is ted * tn tas-o setatieship one object is PE bject is behave fike “tepeocka pepe eperten= Orel ee obec: ' AE Inctantiotion The process of Stoning the object” address into 4 he “Ty stantiation . object reference woviawle 1s Keown as Example” lass Pen { peo P 2 Pent I} , Ad \ eraser 6 qe restanbiatio) 2) Bony ty bady Ingran Hokie + Types Has-o petarienship: Y Composition Tear Instantiotion) 2 Aggegetion [6024 somranviatien) HBA RERRARERERD CH compos iefon += otf one object fs Comper aependi os Composttion "| on another Object” 26 know / p > sere, one object commer exter without another objec eects ered wen tbe help of “Ear S composttien con ack wstepe to achieve commesition by iC Emly tnslontistion :— ps ot for in” BEG “ step s:—Cleate te blue por for “clependent- 0+) ld cai ff tnat chat my) acy 1— Create He dueprins fr “dgending ones” Stepan Cieate depndent gfe of oye tefevence vavionle [pire non Ghoti variable’) Gocide ctpeoetng dass Step ounce Cee class “ongmuctory 10) ig preg for Computing -— package Pav Class Engfoe te the chip ocdtieas of clpenclenk class Porbts process fs neon 05 “Cou! 5 Create the “object for Ce pere¥) dass ” rd —Preees? shootfation ” class the propetien of potr —the cay euenbitin a relarionsh'p; Sting $oeiTYRe Engine (String fueiType > a Nol d sphis: FuctType = Fuel YPE* y chcc Cov “chieg brand; Se Car ( sting prard, Shing Nuol “apyigs brand = bards agpis OMT Cobuts 2 new Engine (Ake TYPO), 4 “~rasnaton, _q rewrionship jour, Shieg sueltyre) 4 paeiic Class Dilvev t ps vm Cs att) t Cor cl= mo (ow Ciera”, Solace”, “vies” D5 in Cet bron) Cex cotur yy S-0- pte Cove ds so plo Core Fury; sop C-------- t Gay coz new Car Crpuai” Subite’ "elechic"); Sop Cea brand); S-0-pln ( ¢2 Colon); Son Ces €): so pin Ceave: fuerrg1e>s y opi emw crlow) eck 1 ioc) er fa) oieset wey ua Seer eal [sal Dua aon eta) _ycasuss Tn ene" ates elecine er Develofey Nasa Laptop: class Loprep t peveloper oper, oegerain —_cegeentent™ Shiog brond Loprep Cohing bard) {ter bts: brond = bord > class pevelope” io ing Cole? hing PRET Laptop bs Devereper C al { vol Cavour, Shing PE’ Shing bron) uybig, colour 2coeet avis. prree = Pee Venes) Leper cana; a) meronsration y y wer parite cle m A pe mc ats) ew Deeg CBE ES f pees teveleyer al so gn (al edow)5 § o-yte Car pices sof HO a Y cor glo Cautevand)s Biri ebnnbeen HaRB ERED ORE ED 23 _maunsves = re got 100 :— bres 7s keoen iolly expendiog 0” ovother on} sr ore object fo TM as “aggre geen et Con jd ttere, ene OFF ; ca moe Cyesor~ exis whheat™ arether Objet ageing otine -cepentent) Ex Person HOS a Book nthe help of Baq wnqooa, ogy ee “toay smatant iotion”, rege sg cone “ages 9 1S “dependent object” Gan te cchieed 0H Instantiation; dre blac pant fer steps: Crete ep ss Cae ge ucpant for “depending object” cacate clependene” “rye of obleer se ferense ste step sty: voriesie [NENP) incide the cteperding cloes tncide the cteerding closs “non-state melted mite Cbecr adetees cadent- clo ee ° Ah TIEN poets alle Object or ctependting HEE” af Hewes whe paperria of be the Claes Person-nosma Mobile [esompte 3. — blue pink for pendent ‘oles 4) Create gacroge nso seloanthi p Class Mobile dounte fs Moot le CShG bard, this pond = beard + pre prites double pate If nis y Menno ng ee 5 pe: ciate tpi fo cpg le Clase Peri { Shing rome | ine ove Mobile mn; [] tree er (shiny nome nt oye) t a relationship Ieor ie nome = ame *, avis age = O96 7 3 ' otic verted . tgs: Creare “He Hon Mobite (sing brood ,aeinke eye nns M punntc vote bf q (Bord, price ds inctastien Comp) soz vee Mobile Konto y 3 Closs Driver : peeves td) fi eeper yenon ple neo peuon (“sefite”, "957+ co: pl Cp nome); 1 ath go. pl Cpl aged Moa 5-0: ple Gin); JJ nal) yy fo. plo (t—-

You might also like