You are on page 1of 25
University ob Inkbormation Technology And SBence Axsignmert ~ 1 eet a Cowme code: | fowee tttle “Obgedt oriented programming Language Submtled to: Tanzix Mehedi shawon Submitted by: Nome : Md. Rak Noom Tonmoy ID : jol4s550IR | Batch: 45 SemeteN: 3nd (spring) Depertmert : IT Scanned with CamScanner ~ % Polymon phism \ pol ymor Phis7n in gava: he work polymonphison ameam having many 407m, In SimbJe worda, we tan debine polymorphism on the ob Lbs o A menage to be Aiplayed in move | Hon. one. donm, ‘Real Lhe example e polymorphism : FA Peon at Me Same dinve Can’ have tilh vert | honacteristic. Like a man at He Same time ia tober, a hurbond, an employee So He | *4me perwon possen dilberent behaviowe in Akberert siduabione This i» called poluporphign. Scanned with CamScanner Polumoxphism i conaidenod. on one ds He mbontert beadwren ot obdet onierfed 7 Progra ming, polymorphism BC Se ae pobomm a single adion im cabbenert wags, ‘In offer words, polymorphism « allows You do oebine one interbuce and have multiple implementations The wort ” poly” means mang and.” morthS” mecna koxme, | Son at \pmeans ; | many deormves Say wh Scanned with CamScanner Ty Java polymanphism 2 mainly divided into fwo #yPea: ajcombile time polymarthism: 14 do abso known an stedie polymorphism . Thio #4Pe ot palum onphisie as -adlieveds by dunchion overbading on operaton \overhacling-. ee { eden void ton (irda, ind) void 4un (dana overbadling- overwudin g Scanned with CamScanner meted overloading 1 when there axe multiple buncbionn with same name * bit dilkerert porametera then there buncions Wi seat 1e-We OT oad. Furnckiom can, be overloaded Ly change in nomber ot » engumenta - ond. orge in type of corgumente. « 7 Example : By using Abb ort dtyper ( ote angumerte Scanned with CamScanner lane multiply Fun £ sdatic int Multiply (ind ay int ry) \f MAA by - b Stotie oulJe multiply (doubfe a, doubfe b) { Neh arb ; 5 4 aos main f Pidlie \statid void main (String l] ang) at oto wats t eek pad ) > el acim Sa ata Da nln Scanned with CamScanner BUstem out pounttn ( multi ply Fun. multiply (2.4) ) 5 multiply Fun. multiPfs (6.5,6.3).)5 | openaton overfoading : | So — Java abo provide option 4o overloack operator . Fox femble we can make Me. opoutor (+) ton Shung claas to concatencte two | shings. We fnow tyt te b tHe cdldilion Scanned with CamScanner operator whose tack ir to Add two “iy operands. So a single operator ‘+? when y Placed between sting oparond, them. In Java, onby “4” operator can be ovetoaded : To add infeger To 60% comote stungs Example: avs openatox OVERDDN J void operator (string’ str2, string sdrz) 2 stung s -sftrnat+st4n2; j Septem. out, printtn ("con catinated Stung —» j oe voick operator (int a, inf b) f int @ - ath: Syptems out. printty) (*semia' te) Scanned with CamScanner fain § a a “ “pallie stalie void main iin (Shaing re Yoox i operator OVER DDN vob4 > new opercter | - opertadon 0 VERDDN (); igkdwaxd ob4. operator (2,3) a tar ome sechayde® cal . 0b4 ocpenaton. (: Joe! no Spdge yiev qn ot - Tet pagle + Seka, 2 enwthe Lo dpotar sin> 602") NLT Ane sesh at Pi nih Scanned with CamScanner 2) puntime polymonPhism : T4 sMdcabe Venoen method pispath. T+ + a call Jo He aa Dynamic poo reas in which G tun ction overtuidelon -melhot Ar NenSvek ot Runtime . Tin type of polym onphism achieved by IMhhodk ovo clling. An method oveniding » on He other bond orc when a Aenivect Lae hon 4 debinition 4 ove ot te member | kon lions ots He dene clas. That hace | ote is Sait to be \ overridelor . 7 Scanned with CamScanner Example : laos ponent J voi prt () 4 svatem out. printtn (* Peorent class’) d2Fa 3 \ ches subclaes 1 extends parent 4 void. print ( ) { Septem. out> Prindir.(“ Sul cleos 2." )} | 3 Ms | 3 ars Subcleas 2 yi A Panent ! voit print 0) ) (are Sytem. out. printly ("sub clos a> | sie $ - ‘Scanned with CamScanner elacs Teat Polymorphism 3 ¢ public static roick main (strung [] 0798) Panent a; a > neu sub chaos (5 QA. privet (3 Q > new subclass 2(); a. print ()) cee wel 3 : 3 * ; Output : subcloos 4 : on a * Subdloes 2 - os . AY oo) os 2. iy ake Scanned with CamScanner Tnhouitonee Trheihonce in Tava: Inheritance % om importont pillar or OOP (olgect oslentes Programming) T4 4 the mechenisn in Java by which, one can » 2hlow to mot tHe teaturer ot onofer claao. Inpertent tovninofog : * supar_ches: The claar whose beotwres ane inhentleR in known hes , on huper | F Sub ce: te clin Bot inheuh Ho offen class in known an pub cher the own Abielble en, Scanned with CamScanner Sub chaey can aft it $$», mehod> in addition 40 tHe pupeclads hiclls ond mebhools, ¥ Revsabuity: Inheritance support He tonrehbt ot “nevsabiliby’, when we wort to cnecte a new clas ond tere 4» aeady a claoo Hat incbudey Some ote He code Hat we wort, we can dbenive \ OU neu clas Lrnom te ex) sding. elas | By, doing His . we ee Neuing He 4ields onl mefbols ot tHe existing 1] day How Jo ure inheritance ™ Java: The Weyeot med +o. inherctomre.ve extencls.. claw deuved ~ class extenda bane - laws : 4mdhod ank tiellr j Scanned with CamScanner Examplea: In below example ots inheritance) “Uae Bieyele dn a bare clam, claw morntam Bile tn a derived clas era oy, extenda™ Bitydte clars and. claas Test 4 A ariver clan to Mun Program. claws Bieyde q x Public int “gear publie int speeel: “public Bicdele (int Jean jt’ speed ) a Yeas Se RRR Hin, Jean > Jean: Hao. Speet > Speed: Scanned with CamScanner speed -= dexement 5 i public string toString ( ) 7 © ndunn (*No ok Jeane ane "+geas 7 NY ” + "Speed ob bic¥de ~ "+ spec J, 3 c laos moontaintike extends Bicycle 7 pubhice TF Seat Height ; | pulfe mount ain bike (int gen, int Speeck, ; eee stant Herebt) i Scanned with CamScanner Sup ex ( gean, speed), Seatheght = star height ; $ public void sétseight (mt newvalve ) i Seotheipht = newValue: “ Publie String 4o Stung ( ) 4 se (suber. to Stung ( ) + + epee height an t+ sect Height ) ; Bs | a s\O 1 w\ dog ee a Ss ee Scanned with CamScanner public claws Test ; puble static voick main (stung 079017) ; Mountcain Bite mh 7 ew movrtaim Bitre (ES loo, 25) Syptem. out. Punt (mb. to Shing (ey) 5 3 5 oud put : No of Geam cane 3 Speed o6 bicycle loo seat height Mm 25 Scanned with CamScanner ir pats Types & Irhenctamee in Java: ee Ol ae Below ane the dikboort typer & mheritence which an “supporteR $4. Java. 4. Single Inhetonce i In single inheritance, subllasses infer? He teatumer ob ove superclass. In.» image below, the vlawr A server apa bawe cher ton He deuvek. dow &, a P = single inherchance | Scanned with CamScanner 2. multilevel Inheritance : tn moltiter el Irboritance,.a douved cles will be inheriting “a bare claw and ar well an He derived clr bo ad on the bee dow 4o offen Ler. In, below image, the choc. Bérverc,tir syewi bone lias hor Me derived \:cloor B, which in Aum sover m « bore cho br Me Avvect ars |. In Java, a Laer camof dine thy (Accens the Pland pane ri’s elo Bare chaas [a] ' | tntormediatens eats Deonrived ms ee Multilevel Inhenctance Scanned with CamScanner sioner chieal Trherfence + Tw bierandical. | Inberitarce, one plan seoiver ” & Supenclas> (bore class) tox mere Hon one sub claws. Th below image, the claw A Seven ap a bore class 4x tHe derived Lars Ce Ore : Hi ean heal Trherifonce Scanned with CamScanner 4. multiple Inheritence > In Multiple. infeniferce, one claw can have mone thes, ingert +eaturer Taya, We, can one Supercaes ank dnom alt ponent charern. In adhieve -multple. inferitonce onky Aynough Trterbacen. In image below. bees ¢ derived bom imterbace pf | lant GB ultiple Int erbace Scanned with CamScanner 5. Hy byucke Trterbace: Tin aomixioe two on mone ct He above AP” ot inheritance. Since Java doen t support multiple inheritance wilh karrer, He hy brick internfance in abo nof possible wilh cheser. In Java, we can achieve hybrid indentonce onby “Broubh > rdoibarer. Scanned with CamScanner Imp stant back aboot inberutance in Java ¥ pebault superclae : Excebt bgot ¥) whic Jan no Suberelaa, creny hae one and onby one dinect S perches, ™ the absence ob any oftren exch li ccf siherchos, engpactees is irbliclld a subelors of bded choos. + sepordns con only be ome: | 9, superbe cn fave ong number ot subdkarser. But a subelrm cam Have only ome superelaer, we Newbee Save Loe not 32 Ppoml mulliple interitance wif Larder. Althugh tp ivterbaces, mulliple inberit + Subportet Ly Tava: Scanned with CamScanner ee H Drheoniting constuuctone : gs ubelaas imbeoub alt the member (4iclds metho, and reotect laren) Anom i suporchaen, tomdnudone cro not members, so Hey are not inherited by sublasrern, but the com tnuctor oft te supoicher can he invobeh boom He subchaeo. * privete member inheritence : alee - - a doer not inherit the private memboro ot ch parent Lae | However , At Ske superrelaer fi public on profecteL melhooks Fer ace enoing th private tielle, Here con abo tbe med by the subclass. Scanned with CamScanner

You might also like