Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
9 views
2nd unit Java
Java Notes
Uploaded by
medimvenkatesh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save 2nd unit Java For Later
Download
Save
Save 2nd unit Java For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
9 views
2nd unit Java
Java Notes
Uploaded by
medimvenkatesh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save 2nd unit Java For Later
Carousel Previous
Carousel Next
Save
Save 2nd unit Java For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 51
Search
Fullscreen
UNIT-2 ——— Tahee: ee ' Basics, using Supes, Ceeati Maltievel Hresace s, mg, apes mg ropa ch Usin x) + Method Dvessiaing, > Dynamic Method Diopat’ yy 3 Abstxact ¢y S? Or 1 sith Tnlesidance, . lasses, Us 1g Fi _Packages * Basics ., Lending Packages, ond Chasepath, Access Restection, Cnrpacting Packeges- Fraleshas + Dekinition» Smplementins Antesfaces , Extending TntesRes , Nested Trex. ce» Apply no Tinles face 7 Nosiobles in, Tarde Paces - © scanned with Oken ScannerTnheritance : | Ta Tan, Liahetitance ts a Concept Lat acpi | Lhe peresties Prom one class to Dies classeS* yop exenpley the YelationshiP beta Father and Soll” : ~sahesitance in Tava is & Process acquivingy all Fre behavianss oF a pasent Obiect The Gece & Saveditance im dave is thet, neo classes con be constructed 02 toe oF OlNew ONES yan con se the Pawent class pethods and PsrersUS then yeu jaherit Pom on ex cling clsa- you cart alco ads casivoretl Relds and methods 40 yang ose | Class: & en ~ Pent a ss “Band Puen —~ Gypoenh Poser Fad set pute Sytox na class Supevclass 4 = 2 Cass gatelass extends Supescless i z The extends boremtd iadirates Lake You axe mal a reed cee Eat dees Pom ant existing class - Sg mbesited | a A class which jnhesiZed te called a ® Phew! ce capetclot& 3% Base HSS) ond the pew class 8 called Child cubclass of Detived cle88° © scanned with Oken ScannerErowrple Chss Exnpleyec Mint Galawy = 400007 Class Peagarmet extends Employee L mt onus = loco 7 Public static Vow eran Gesing 252) 3 ene Pregsammes P= reco Pscgrrmmey System -ouk- psint Oy P-salessy) : System -ouk -Peink lu/p- boos) : Ci System + cuk- Print In(*Te 4 bin) 2 otal Salaty 4 sala Pe 3) 2 ” é oe Dy ole | 4,00¢0 Loco 4.1000 © scanned with Oken Scanner— — pes of Aahesitance In Jove —— >. hm . “These @n be Pie tyres of Inhetitance in Tava - 4Simle eresitence Multilevel Srhevitance 4 Hiebaschical Tahesitane Mutiple Knbesitance 4+ Yybsid Kinhesitence Sige Selene — Sua , Binge inhesitance wefexs to the Psowss_ 2 cending & Sinle desived class feom a Giggfe base Clasg + TAS a Simple Poore oF Sihesitance hee a Jase can WEA PEAEStIES (Vesicles) and behaiass (Mretnods) Peso only, One Super Class - [ERE] Paseat Rose | ures TEER) Chid [Derived / Guts Syphax chss A { c os B extends A i A isthe Base cliss Prom A Base Cass “20 ase Desivigg acess T3- Me ase cteating a Single desived ches Pom a Tingle Se Claw So the the Memes of the base Class) Can be accessible Fsow the Defived cles8- ; © scanned with Oken ScannerExanPe class Arima! § (bid cot C) 7 sag"! Gystern out: Penn (‘eosq') a Dea, extends Animal ia baskl J . Syston -ontt -paub in (" bashing’) > 2 i ehakic. Ve MON (osing )) Xs a= rew WeyC ) a bsnl )* g- cot CY J y “ale Sbosking, © scanned with Oken ScannerMuttilevel Shes lane =in avo, Multilevel inhesitance Beress 19 Le TOS Of cemmting a class that is detived som oncthey” depied class) Creating o chain of Classes - moon [ese 71 OW L Pacer FeoRSE'B] |} Thtesine dake (as Bly Class SS ching [elas C) Chas A sewes os a base claas Rig thedetived chss B iphich ‘win Sehves as a base HSS LEAN esived Chassc- Syne Class Grand Reser Sass Pasent extends GeondPaterd Class Child extends Reent a + - © scanned with Oken ScannerExerrmle 4 “clase Animal a Leia et CJ z stem-ouk- Print Mn (“eating”); ; oS (estegy); ase Lea extends Animal Wid bas CD Teyetem-aut-Peinttn (“tasking’)s ee Badudeg extends Dea, L Ved sleePC ) “Oustem-oul- Bi Qn (‘slecring’) Yr + PuBic Sakic Lid main (Shing, aussi) Fam, bd = nets Babubes (_) - bd gleePl SF ba+ bath )F i ba Catt 7 3 ZF ae Sleeping Yoox kin : FI aay d © scanned with Oken ScannerMiesschica) Sabesitonce ain Tovey hiewaschical inheritance wfers to the Pores oF Ceeating multiple Chesas thak ase detived Fam o.siggle base clogs Tt Foims a hiemschy of ClesseS Dhow a Gingle Pasenkt class & used “Zo Create WMurtiPle Child Classe$ « _, Parent /Base atl ot Cy) (Css E) (ease) Cit /Desived Hee, A is the base css Prom thie Class 22 axe. desiving do classes B is te fist derived class and cis Serond detived Class.” Syytax ches Pasent $ Chas A = i 3 7 glass chu B extends Rent — gx) des Bexteus A 3 . ses CNC extends Past = cadents AL F © scanned with Oken ScannerExomtle Class Animal Void eat C) $ pterroaendtn (eatig’); 2 Class Dey extends, Animal Void bos () Xptem-out -rsinbtn c "Basking’); Ba aren Cat extends Animal "ys mec ) soe cu printin(" reves") 5 ore etatic veld mein (Gtstng exst) z Cock Cane Cat ( 7 Cmecsws( )5 C+ bakwl So creat Ca OP meow des KiNG ating © scanned with Oken ScannerOO Multiple
indesfoce A u Brrface B enters ? iL Zaeshace = Jas D intents 2 3 centers & Bc © scanned with Oken ScannerMultilevel Hiesssch? ey Th Jao., you on create 0, Mantileve! hiesscely- @ deFiing a SeBieg of classes, thal inherit Peom | ie Asethe? in a HiesoXchical Manes’ This Mea! | Hat you have a. base class (Sores chess) 2 hich is tented by one of rmbe “Tnbesmediate ClasseS Gobclassed) ond these intesmediate classe CFV Saga de Pasthes octended by 0be% classeo This cueates & Multilevel inheritance stsuctane” Gant Reent ap B) | sntevmediabsty Class Pmurtilevel — The Peocess oP creating a Class Faas dawed fom srother cbr ved Chas.» Comey ) Schaaf CbebeS © scanned with Oken ScannerExanPle class A © ss mLiC ) Toselom- cut: poitsa (“This is class A’)7 3 ce B extends A Tu md) Foyer out: peinetn ("This 2 class wh class C extends B t yd ma( 7 y Peter ot Point On (‘The ig class e) 3 a Public habe Vid Mai Gtsing exsfJ) z e ajanew 6s obs-mil 4 Ob)* m2( Jy ob\e 3X4 © scanned with Oken ScannerSupe? The Soret keyword is used fax aessing monlesS [Lirstance Vosiables ,methels and constsactoss) oF the Pasent class Gores class) Prom sithin a ChAd class (SubClass) + The super foytio be Specified in oie alae co How the Sunes Keyaosd is used a Accessing, Rasent class Inetarce Variables, + Accessing Rasent Class Methals, + Accessing Pasent Class Constsuctoxs, Accessing, Fasert Chess insiance Variables Ae con use supet ' to access instance Variables & bre Patent class shen they have the same Vesiable Names in the Subchss(child Coss) - This SuPew Leynosd helps yu distinguish beween the Subclass Vatiable and the Supetclass Variable int x=30s Aass Child extents Poort int X=207 Void mi C ) int x=lo5 ; sat ans Se as oe oes out *PINERM (SURE) i an SAabic Void main, (Ssivg ons) 3° CRE c = mee Child )> Bg omtos V3 @ scanned with Oken Scannerine ke mag” Acceseing, Posent Class Metres = (oe can Use Surev “to Invoke Methas oP 4ho Posen} Class ohen these is method Ovesidin im the Subclass - Tb allows you to al the upesclass of the method ex closs Resent wa mit? prem out Penn C Helo Parent »; a : a Child extends: Pasext Void mit © ) Svpes> m4 C5 =e out - psiattn ("Hello chile’) ); a SABES VoIa main, (Geing axgsf 2 CRIN C= news Child (5 Comt C05 3¢ 9 Hello Pasend Hetto chird © scanned with Oken ScannerNNN Alccessing, Reet Class Gnstsuctof dae can Use Soret -Lo car constsuctoh oF the Rixent class Psom Within the consbeuctes of the Child clagS- Ths is Often Used to Weuse the TniMalgation Cale in the Supesclass crstsuctor ex “class Pasent “pot Oo) Soon ont Paidn (Hello Poser) Jase Child extends Pasenk 7 cra c> q supesC LI \ ; Satie ont Fe ( Hello chile); Public Static wid main. (Sting asaat » Chg c=new Child (Ir a & of? ~ Hello Resort Beno child © scanned with Oken Scanner(Trew ewe eeuuuuer~- Dye Meth Disatch ww Jan Dgwric Med Dench is amsharism thet drides, Lhd reoriented cit be calle) ob Sankime =~ ON Dapomic method Ystatsy is the way iM which the ll to an Chessidden method js wecdlued at ‘sun-tive Sathes than | Comble fine - Meted Oveesidingy fe the day to implement: Pignssprisn , mae secieally Guntime PolyrmsPhisn, alco called Aynamic method Aspach - Hee, we hove « Yosent Class ference Aria Iyhidh wwofews to She Chit oF ¢ To Based on the Obiect being Hewed, wt Call decided Lhich wetted dill be Galled- Persea chss A a show) Xo tem ot Paint Le (‘Seside A); JIéess B extends A Ya shad) 4 i) Ciglon-ad-Paink dn ‘nse Bs ;3 © scanned with Oken Scannerchss C extends A Void Show ) Suctem oet-Psintn (“Insite cy) 3 3 Class MPecxparrn L Public Sabie Ved main (being oggC3) A a=vew A CL B b= teu BLY C c=new cly © scanned with Oken ScannerMethod Ovestidin Ta Ton, Pathe Dvessiding 6 & ceoeept that allows a _Subchss 4 provide a apeciPic implore! vation Fs armethed thab ts aleady cfined 12 Ys SuPesclSS- When a Cubclass dohines & LOM Ahe Same viame, weluntype and Paxoneley Hist aS a meped initS SupeschSS_j7t is said +o be Ovestsing the SopescasS method - Melek Oversiding a Pundamottal Keatuse of Pelymasphiol in Uniect Deiented Peeguamningy- Snax closs Surs(lass Lear medrathme (Peamebess list) TL s cass SubClass cxctends SopecClass Tcramtyoe metedName (Taasetss bet) g eu ond hen, uo 0S ruse retheas having Same Teme cane Saget (Pasmratess) in the SuPetless and ee Pasenk class diet 1s veced to Gi\ the hnethod then the Patent class method Ai" fe cubes * Dbeauise ) Pach class Ohjact is Uzal fo Ge) te Mad yen the chid Chass fethad Lil hecxecidled - © scanned with Oken Scanner a gsee ches Paxent t a deploy) oyelem, cat spointlin( * Rasen mjet ecoeatel 5 Foss Child extends Real L Void dis Play (_) i indQa (‘Ch rethod 8 executed), eyptem cut Pinta ("ch met exec public static \eid vairt Glsing asf 2» CHS ¢ =sete Child ay c-dishloy( 5 Pasent P = new Pasent ()5. Pp. display ( )> © scanned with Oken ScannerAbstsoct chss A Class that ig declased using “abstsact ” ig Kron os atebsact chss - : fet in way an absiact class is aq Chss that annot be inctantiated dicectly but can be Used as a buepstt. Pos othe cacseS + Abstsact Class Can cobain Instance VawiableS Uy Nesimal MethedsS ond akstsact methods - Gustave “Gpatsoct class ClossNome Abs boct Met 7 Ta Tao on absttact method is a Methe| dclosed Wi or absteact chss but chesnd hove a cerpementation M thal: clogs Atstsact methed3 gse vncor to be Ovessidden by concsee Cube Had exterdthe abstsacl fags. Absteack methds oxe declased vst, -the ‘abstsact” Keyroot] and voithouk Providing body * Theyend with a semicolon (5) Sywkax abstact getuin Type ‘eethod Name (Psnetos.tst) © scanned with Oken ScannerExample ctstwact class Animal okstsact Void Sand()7 class Dey extenas Animf Void sand () "Syn out: Paintin Basking); mae chakic Void main. (Basing aept3) ey 3 =vew Deg C5 Argeundl )7 3 ea ont Basking” © scanned with Oken Scanner=> Fina | sin Savy the Aral is a keyed It is ved do mndicte Lhe a Vasiadsle , method (66) clase #5 Vinal 06 Unchangeahle aftes rt hea, been defined - 4 Final Vasiahes Huhen Yau declave a Vasiahle as 'pyy af 7 Th means Lnak its Value Cwm ot Longe, Powe st hes been assigned: i chara ex class Finalemu — chalic Ved, amin Gling gst }) ; 5 Roa inl x = 04 Xx toy 3onm out Paina x) OP ~ Ct + Final Methods ahem You ceelase o Methed as “Pral” mn a class, it wens that this method Genet be Dvessidder2 ny cultlass + Subrlesse8 ose not allowed 40 cat a diPPewnt plementation Los a Bucy’ methed * I © scanned with Oken Scanner€y Class Pacer ose wid show ) Repdem -eudeprindd( “Hello’) Class Child extends Reent i veid chow) Noyyelemn-Ont- peinlgn (“Bve') Buvlic static void main. (Glsivg asap J Sanu cone Child) 5 0 chow 37 e Eos Hf Final Method cannot be Dewsitten by child Cb&- 4 foal Classe) When you declaxe 4 akS as, ‘nal’. it meats Prok Wie cess cannot be exte class: extent} by any Othes © scanned with Oken Scanner‘| ex" Pinel class Poser void Vishay ( J Stern soul Psy widen" Paver’); g Jess Chad extendS Reet t eid AsPlay C) *oyetem “out Powe fn (‘che a’) ); | Pubic Sraric veid main (SAyive ahs \ as Gig ager) Chi ¢ =newd Child C3 c+ display ( J y Exvoe Snot Clase cannot be inher tel Extend by anothet cloS§ ~ © scanned with Oken ScannerV_> Chet Clas& aa Wave, the Dbiect class is the tool class Re an classes Evety class in Java is dhisect} ‘oer inisectlY dosived Fsom the Obiect class - x eee pol extertd ONY thes cloi& tenitisadiwct | chit chas oF Dbiect and Porters gnothet cl8S | ren Hb iS indict devived - \ Dbiect clog wthe ave Ppomnnig laggy? | ig poset taside the \eva~ lang Package - Disectly Desived cha (oO) thy Desived CAS Cc indisee @ scanned with Oken Scanner+” * + + Methods of Obiect Chss void Pinarize L) Void rotiPu(_) Void notiPyAu( ) Void anit) F {is Obiect: Gated lee an Yous Obit is Secyled- benlkes, Up a Drsead , cxiting of the imoking Obiact - Lakes uP all thiealS, Aniting on the “woking Obiect - Causes the Cessent thsead to Coit ) Unti) ovothey Head nobis >. >oemame 7 e Method | __Desexiption. 8 Class getClass) Retusns Class class Obiect- 8 int hashCode () Retusre the heshaae Number | S Pos obiect 7 bectean nis(Ossct ai) Compases, the given Obiect to S sss Obiect - & Obiect cloned ) Ceates amd wetucns the exact | | Copy of this Obiect- . Ole, : Sbsieg toString ) Retusns the Sksing Representadian | © © scanned with Oken Scanner , ey> Package. . A Package tenets put a Soldee stouctuse at contains a qe Pe elated CSS Tacos, on Sub Poses) accosaing to the\t Supctionaltyy * Sr Provides © OS to cBgaSe and sakes face to make then &si esog ond sabes faces of a Rackage ase an the oat that can Se Use Severo? Me ihe 22 need chert: This sevsability ed Kase rakes, PRGIAINT cast - athevefose, lhe? you create any SoPtanse Of agplication joe Prsegpoornn it language, theye Conttein. andseds of thorsands J individval Claxy and antesPacd * SO dhey must he 08 oni, 28 pul pekege Sgonined kage name to make ho o reening ~ senbe and Sevsi in Othe By these Pack in Othew Progsams Could be es © scanned with Oken Scanner(s nox _ Package _fachagp eines 4 Package - Ths is the Keyword used ce Package « & Package name — This is the name PF the Pac Kage « AE sheuls Pallets Save Package, Neering, conventions (ohich usually tevelve using lowescade lettess, ond ceresatitg Package levels woth Dots Ceo le — ' Package ephtwate + are: website xy +to declae Class Castell t =n this example, the “Tnstall’ class is declased, Xo be Tube oF the soft oate - Jain website Package’ © scanned with Oken ScannerCrore Package sof twnse wJava + website; Public class “Castall L Public static void main (St6g oget) —_ «out - pint la(“s2elcome to Pc hoges')s 2 é How to Gmpile Java Rackage jovac -d * Gilename Saver & Jovac 4d * rstall-Sove “the —§ sisttch eqecifies the destination Dhese to put the geneted class fle: TP you cant to kee P Lhe package within the Same disectot§ sv aan ise -(aot) Hos to sur Java tackoge — Yara. Packaspnaane: filename Ge: Seva softsoatse Java: website +Tnstall © scanned with Oken Scanner| Types of Packages in Tose Thee axe mainly tao tyres of Packeqes avilable in Java - They ase * 4 Sr Balt Package (PeedePined Package) & Uses defined Pac! Ain Burt Pac kage (Pedeined Package) in Thre, PeedePined Rachages owe Pac hages Het ae clieady defived as past of the Save Shon tosd Lbsaty’ and they ose available -os use in any Je pega, idk the wed fee aasitiona| Setup- some Commanlyy Used PeedePined Packages in ve include : * pve lan” a dove uti] # Jona-i0 + Java -abt a Java applets # Java-net cava lange Yana, stands for language » T+ Contains Obiect chys, Primitive DatatyPes math class» Stving dass 7 Sistem cess , Exception claggef ond phveads- @ scanned with Oken Scannerweve-util ULI] stands fe utility T+ Gomans Gllection Gamer (List sets Mak Date and Time Viensling (Date, calendas’, nnezrd) Rendon CSS. Seanee Class sShingrhenizet Bisel ches Vects® ChB - _Seva-io 10 stants Pos —raput and DbPub “Ft Conbains, Skweams (sapubseseam 2 OubPt giseam)s File 2/07 Byle Skeeams ,Chavactes SixeamS SBurfere ob Shans - Jove 09 b jp - Quot Stands fos abstsoct windocrteel WA <4 contains GUT (Gsaphical wer Tntes s / clement guch ag button ®, enusg bo Sova. -arplet . ie wed for MY opplets Java net / aa starts os Metworh Uses defined Package (2s) Custom Pochage The Package which is defined by the Used iS Qlled Users-dePined of Custom Package »
Java PryPack «PecgsamL- © scanned with Oken Scanner> Seting Regs oo Sy Boa inches the impact statement 4o bting Cestaive Classes, o¢ entive Packagg® into visibility» Once impested OQ Class can be wehassed to dicect\y using, Only, iL vue: Th Java, He inpost Heyonsd used to impost iv1_built Od Uses defined Packages: hen a package has imported Le Con ees to alithe classes, oP that Package Using thei? Blame. disectly. Xi a ina Suse Mle, impst Statements 2£6u5 immedi — telyy Fateaing dre package Statement and tease ony Clase dekvitions- Using, an impact Stabement, 2 may imPIE a specific Class o6 atthe Classes Prom o package” > Soposting SecRic ches Lang, an vngesting, Shatement, 2 can impact & SprciPic Class Syntax imps t Pockosgnaime-Classnome- 7 Serpecting atthe Clasees Using, on ‘ingesting, Satement Ge Can‘ynPack ail rec OP a gackage - B inrpist athe asses eR the Yeckere, toe Use a Symbol a Sayitaxe mpest Packoggnamne t ; ingost. Pg -Plge -Classrame/ ; Neve, Prt tebe Mame of a top-level Pie . We name of a Subestinale Package \ncele eee Page is cepatatad by 0 Bt () Finally sHeeihy eae ¢ aie of a Stas(4) eam, © scanned with Oken ScannerPeas > Package youtube “Jali Package 47 Pubic class Packegebera ae void mt.) Sata peint ug (‘Hero’); pee babic Vid min (Bbsng ogst 3) o Systernact-psinbir(“aelcame zo Jae, packeges); 2 Compile > Jowac —d * Rackagsdemo favor Ron > java youtube «Java + Pockage 1 - PackageNeno > Tmmpe6t youtube Java Packaged» RckageDemo 5 Claes Mainldero i pane Astic Void mpiry Qiang rn Fae huggDemo Ohi=nens Pelage Demo ) obi-vni(_)7 a Conpile —> Javec Maindero - fave, Run —> java MainDeme © scanned with Oken Scanner=> Access Frotectiort Th Tava, Access Protection ts «Lurdameal Concagt thet helPS Contfol the Visibility ond acceseitsintyy of Classes, Methads ord Vasiables LOR O “Nava, PE&GSAIL- “This iS achieved! thou the vse oP accers MalPiess , hich SheciPy Lhe level oF accegs that Dthev Classes “ox code ann have to Pasticulas Members: These ase fous cateqssies Provided by Davo. Kegsding the veto of the Class MembeXs between classes and Pacltages,« 4 Same Radhage > Subclasses in the Some Package +f Non-Sutsclasses in the Same Package *Subclasses in dWPegent Rckhades, Access: MediPess axe Public Peivate_ Pwtected and defaulb Java Pavides 0 sange of cays ko acces weuived by these Gtegasies - Any Varia Acla¥ed as Public, could be acceasel am anveheve-, Any Vasiable caclased as Piivete cannet be seen. Outside of its clas Any vasiable declawed as default fh is Visible to subcloKef as, well as to other Cle8828 Mthe Same Package - © scanned with Oken ScannerAny Vesiable dec hie’ os Prlected , it allows an element to be seen Outside of cussemt package, bat only to chsses that Subchss disectly~ eece & Public — Visible fo Evesyone Flom anyahese a 4 Psivale — Visible only withia the Cogs : a 4 Peolecte) — Visible im Package and cubclass evel 8 a default —Visible only witim the Package . 7 . | Peivate | Puvtic Prodecbad | Doble Some Chss Yes, Yes Yes Yes |e Some Package Subchss No | yes | yes “| vs |e Some Package Aon Subchss | No yes | yes | A . DiPPesent Rickesp Subcks | NO | Yes | No No le © scanned with Oken Scanner=? Taecoce in Evo Tin Tao, on inetlace_is sans it Contains static Pinal \ Vasiables and obs! Mechanisrt ‘Lhe intecPace is & ' Thee can be only absbsact ynethods bab ty a Chass ~cpeacl P Meth | Daly Zin Tava, phos: TF the Sub ck i rel miyee mplomendadion, Class- on wkeeace ther His cl even en Paces A Chss con implement O°, numbes oF ; i vnbestace is decked iy vag, the waeetace Heywosd Gaston intesface Z imbesface -Yame > Lye Vatiable-name 4 =Value j type Vatialle ome 2 =Value = a \asiatle name 1) = Value 7 satype metncd mame L (Ree ted list) > Yetusnbype method ame 2 cand “bisrlyge Medel nanert (Pueametot list): Lp @ scanned with Oken Scanner> Tonpemening, Totesaces The implements Heyoxd io used to implement on nlesface The Tniesface Heguord 16 used to deck a. Special Lye oP class tat Contains Static Final Vosiables ond absbsact methods - The Class uses a Heyonsd implements do impknent on indesfoce - A Class Can implemertt any ambos” of mpesfaces » When a class Arle to implement mse re wpebhace , We Use the implements heyoxosd thon 0 ie Pailocacd by & Comma (2) SePasated Tet of the jnbes Paces amplemented by the class Spit Closs class-rname impleme f Syne Clase class-Vame implements andes Pace rare SyinlesRee Mane? q ils inlesface name F © scanned with Oken ScannerPeegaen intesPace MyTetesface Public static Pinal it X=!55 public abstract void mt C1 dias TatecPaceDemo implements Spe wid mi CD ete -ouk Psat ("cacleorme”); Pate Blabic Void main (Stsing, axeE 3) Myintesface © uetoeDee bl = ress TrlesRaceDemol 5 Co Mesias (osx); y F ofp ~~ relcome 15 @ scanned with Oken ScannerTTP TOO O OER EE EEE. Paxson interface My interface 1 Pulic Static Pinal ink X=105 Puttic otetsact wid mi C) 7 3 intewface Myinledace? Pustic atic Final int y= 207 Putsic atabact Veid moc )F Chess
Extending an anberlace Tn Tuva, an intesface can extend anctret inbesoce* JUhar an idertace Ants to extend onothee _inteslort/ » it uses the Fepuoxd extends * “The Syrlax is tye SOME OS Rx inhewiting Classes * When a class, implements OFS intesPare Phat imhesits asothes wiesRace, tt {wijementadiens 4s all metheds epuced bythe fh heriton® Chait’ intesface A Pubic okstact Void mi C7 Public abstsact wid me C17 Fntastace Bextents & T pic abetenct void 30) Class MySrtestace Wplemenss B Fa wtic vee mi Leystern-out Perce ha(‘“rmnplemend, My "Ss Pubic Vad M20) Fe tem our Point (‘ovement me); Public eid *3L) Ssgiemant pita soerer vm"); atic Static Vad rain lxing aegs73) Myintesface Obs =new Myrrteeace( )- obi ; 4 © scanned with Oken Scanner=> Nested Tntesface Ten Waa) a ‘rested jntesPace isan intesface Lhat 1 ceclated within onothev inbesface_, class of axstbact Class - Nested intestacy Provide a Keay 40 leqcally B&OP elatert InresPacey and Can. be used achieve, 0 mese Osganigel ond Stouctuse d desig i? For declasing- 0 nested fntesface in NPRetenk Cxlk - y Declasng as Trtesface Heide Arthes Tatey: Teclasiq on Taevfaste Tite am Absteact clays ay Declarnigran Tideslace anside & Class - Day 2 Sele ine tied eve inlerface Intesface Name T “interface piste raerface Mae g EF vechese Age isa dis Play (7 intesface X72 Tapia ressogel yy 3 De posted sakerface Demo implementtS ABL-% YZ Pie vad delay ¢ J Loystem-out: oink ( Heuo") ; © scanned with Oken Scanner© Public ved messagel) — ponimasrnt (["workome Nested utes faces, 5). Pustic stele VoL main (Steins ager) P pars SaeePecdDemo DB = rete Needed eslaceldne( ) obyemessagel D3 a pps dtoplayl 4 & pase obetsact on Slechace inside an Drctrack cb85 a Selectoce SS class AbsdsaclClssNhme t ce —ytedace. Nome 2 3 & abstract ches \ T ghateack void mdl2i intesface Nested Sndes Pace Demo 4 onsteact void mal’ 3 a NestaDemo extends A iwplenerts NeobSinehevo 4 vig ntl) ASytemout parla Pek) d © scanned with Oken Scannerwid mad? : e 5 ler al priakin (‘Chil puble static Void main, ( Hsing ager.) + atlDeno 0h} = nec NesteaDemo ( )7 obimeC 4 obs: m2 y face inside a clog Declaxing an Dalesiae WEN — e Claas, cosshon” = Joum @ Z pslare Sesto Le $ Fay 1 Coe Spiostace MSY 4 ay ig eb ge ements HICHINS z 0 ivr? class ested ery Lane wid anessagel oem cout porn” peeves) v © scanned with Oken Scannergee otakic Void main (Bbsive, ost) | KestedDemo Ob) = Nested Dewro tL | Glos megsanel 27 SGApplying cinteslaces ™~™ 1 in Tava, avelying jndes os i aes of iopienmning bat aoe the mese intesfoces Githt gone — mn a Class > intesPace Myriedtacet na) iat SF t Public atari Purlic apstsact void mi( J; z atesfece Mysaredace 2 Xpatte toric Pinal int Y- 107 pe c abstsact Void m2 a Joss satexfecdDomo imnement® pysnrertacel, pyre % pustic. ya C2" Teper ont PIAL % . Pustic void. mec) : sata’ besos’); etem-osd pent C elcome: TOES LZ ie hate void rein (Geng Bee oD “ Deno obj =new —LabesheeDon0 65 parm Ce ae ores 05 pa OL v ee ot “psint fa oni-¥ p g © scanned with Oken Scanner (a Pocgrameitag’) 7& Tateslace My-satesface L Tanne static Pinal Ink x =1S5 Pon abstwact Ved mil); titeclace Myaebeshace 2 ipawe static Fuad wh Yo Sor pubic absesact Leis m2 Jr z ines ce Myaabeshace. extends MySnlertacet, Mires Dante static fad tak = 257 Public olsvcact ves mC JF + Clas GetosbaceDer0 implemen 5 Myinbesfa.ce iS pune voia oO Soagter ont parub La (Ararat Ress: veia ne ( ) Sao cok: Poke (‘Aahera’): Jae eis M30) L cub Psivln Ctakshoni’J> System 4 main (Stag asl Dv Zz _ anne ote oo RadesFace ere J5 § syteslacdeme 14 =¥0 Sime sot Cy ad pHa ie y 3 te OF pointe (2) © scanned with Oken ScannerSV 2 =, Do An These centine alobact methnis ard Site Pn! NbGiables - The Visiables dered ia an ivlefare comnat be rod ed bythe clases Pek inplement © the ebecfaac put FE as We as ik defined in the whestace: He Rhoroes ne axe using Weiales ary IES default Coll be Stable ‘Pra Vasiable- Static \asiable iS noth bub Which we aun't be Boith she helP ond a. Beal Vatiabe 's rotting buch the Vasiable VoMe Camnot be Chasged onde 42 assy the ANE to te Vasile oe avid Chay Pager inlesPace Mashs < ml INTERNAL =30/ ink EXTERNAL = 707 int TOTAL ~100; A wid disrby C); mn Student, impements Masks Mi dioplay C) Super out psi (arta) Mass" Gotem oul-PSntSr("Extesal Masks.” wren); Gugter Out: Pe (Tet) Masks, As-"+Exterwad) Cara ="s Tora); ~ sie shale Woid Malin (Stsin by i, 13 sep) Gfudenk Sd =neLs Gfadent ( ) - BA-displas (Ye a d aia © scanned with Oken ScannerDiPhesence between ches & SolesPace ja Joua Class |4 The Heywosd used | to cxeate a Class is “Class” + A Ches can be inctomated ie. Obiects com be cated’ 4 The Class donot Suppost MultiPle | inhesi tance - “FE can be inhasted | Prom onetne’ class- X TL con be whesited by ancthes class Using, the Keyoxos d ©extends’+ M Xt Gan cntaing, Nosmnal Vasiables ,Stahic 4 The Keywesd used to Create an intesface is “intesPace” Lt An Smtestace Gonst be instantiated ie Objects | Commo be created - etePace * The SntesPoce SvPrexts Multiple WAnheritance - TH Cannot inhes it O clasg- i *& atan be mbesited by a class by using the Keyword ‘impements! and it can be ines by an intesPace using the keyx8d ‘extends’. 7 aS ASE @N Conta Stectic. Bna\ Veriades 2 Grol 2 Vat ia fe, & metheds| Sec © scanned with Oken Scanner
You might also like
Unit 3 - Relationships
PDF
No ratings yet
Unit 3 - Relationships
23 pages
1SG19IS043 - Karthik Bharadwaj.P - OOC
PDF
No ratings yet
1SG19IS043 - Karthik Bharadwaj.P - OOC
17 pages
11. FOUR PILLARS OF OOPS CONCEPT
PDF
No ratings yet
11. FOUR PILLARS OF OOPS CONCEPT
19 pages
DocScanner 30 Sept 2024 2 33 PM
PDF
No ratings yet
DocScanner 30 Sept 2024 2 33 PM
12 pages
1683044825934
PDF
No ratings yet
1683044825934
5 pages
inheritance chapter
PDF
No ratings yet
inheritance chapter
35 pages
Chapter No-03.Extending Classes Using Inheritance
PDF
No ratings yet
Chapter No-03.Extending Classes Using Inheritance
18 pages
Vasit Java
PDF
No ratings yet
Vasit Java
10 pages
Mod 3
PDF
No ratings yet
Mod 3
21 pages
Non Primitive Typecasting
PDF
No ratings yet
Non Primitive Typecasting
15 pages
Book 20-Sep-2023
PDF
No ratings yet
Book 20-Sep-2023
24 pages
note8
PDF
No ratings yet
note8
25 pages
JAVA Middleware
PDF
No ratings yet
JAVA Middleware
34 pages
java assignment 3,4
PDF
No ratings yet
java assignment 3,4
20 pages
Java assignment-1
PDF
No ratings yet
Java assignment-1
17 pages
Adobe Scan Jul 01, 2024
PDF
No ratings yet
Adobe Scan Jul 01, 2024
12 pages
Adobe Scan Nov 06, 2023
PDF
No ratings yet
Adobe Scan Nov 06, 2023
20 pages
Python Complete Notes - pdf-18
PDF
No ratings yet
Python Complete Notes - pdf-18
4 pages
OOPS Notes 4th Sem
PDF
No ratings yet
OOPS Notes 4th Sem
7 pages
Hand Written Notes Unit-5
PDF
No ratings yet
Hand Written Notes Unit-5
23 pages
DocScanner 19 Dec 2024 12-23 am
PDF
No ratings yet
DocScanner 19 Dec 2024 12-23 am
8 pages
Object-Oriented Programming With Java 7541-880
PDF
No ratings yet
Object-Oriented Programming With Java 7541-880
64 pages
Adobe Scan 15-Dec-2023
PDF
No ratings yet
Adobe Scan 15-Dec-2023
20 pages
Oop Concept
PDF
No ratings yet
Oop Concept
33 pages
U
PDF
No ratings yet
U
40 pages
Java HandWritten Notes
PDF
No ratings yet
Java HandWritten Notes
84 pages
JAVA UNIT-2 MCA PYQ
PDF
No ratings yet
JAVA UNIT-2 MCA PYQ
16 pages
oops(notes)
PDF
No ratings yet
oops(notes)
5 pages
OOSD Unit-5 Notes
PDF
No ratings yet
OOSD Unit-5 Notes
12 pages
Aaryan Roll No77 Assignment of C++
PDF
No ratings yet
Aaryan Roll No77 Assignment of C++
10 pages
Java
PDF
No ratings yet
Java
11 pages
Java Notes Complete
PDF
No ratings yet
Java Notes Complete
69 pages
Python Linkedin
PDF
No ratings yet
Python Linkedin
75 pages
JAVA Assignment 2
PDF
No ratings yet
JAVA Assignment 2
12 pages
CPP Notes - 02
PDF
No ratings yet
CPP Notes - 02
30 pages
Notes - OOPs in Python
PDF
No ratings yet
Notes - OOPs in Python
19 pages
Dashrath Nandan Java (Unit1) Notes - Alasso
PDF
No ratings yet
Dashrath Nandan Java (Unit1) Notes - Alasso
11 pages
UNIT:1 Þashath: A Pupiam
PDF
No ratings yet
UNIT:1 Þashath: A Pupiam
49 pages
Python Handwritten Notes
PDF
No ratings yet
Python Handwritten Notes
41 pages
OOSD
PDF
No ratings yet
OOSD
20 pages
Chapter No-02. Functions and Constructors.
PDF
No ratings yet
Chapter No-02. Functions and Constructors.
27 pages
Classes and Objects Part1
PDF
No ratings yet
Classes and Objects Part1
25 pages
C++ - OOPS Part2
PDF
No ratings yet
C++ - OOPS Part2
10 pages
Java Notes
PDF
No ratings yet
Java Notes
174 pages
Oops 03
PDF
No ratings yet
Oops 03
14 pages
note11
PDF
No ratings yet
note11
24 pages
OOPSDA23BCA0186
PDF
No ratings yet
OOPSDA23BCA0186
7 pages
Generics
PDF
No ratings yet
Generics
2 pages
New Doc 11-24-2022 23.19
PDF
No ratings yet
New Doc 11-24-2022 23.19
16 pages
Java 2
PDF
No ratings yet
Java 2
66 pages
OOP Practical
PDF
No ratings yet
OOP Practical
30 pages
Chapter 5
PDF
No ratings yet
Chapter 5
106 pages
Ctod Week 6
PDF
No ratings yet
Ctod Week 6
18 pages
Oops Assignment 2
PDF
No ratings yet
Oops Assignment 2
12 pages
C++ Short Handwritten Notes
PDF
No ratings yet
C++ Short Handwritten Notes
25 pages
NCC Unit-1
PDF
No ratings yet
NCC Unit-1
25 pages
Abstraction&Multiple Inheritance
PDF
No ratings yet
Abstraction&Multiple Inheritance
18 pages
C Programming3
PDF
No ratings yet
C Programming3
21 pages
Lec 6 7
PDF
No ratings yet
Lec 6 7
26 pages