DocScanner 18 August 2021 5.41 PM

You might also like

You are on page 1of 7
tqnment=1-————$—$————} Assignment Public abstract class shape Pullic abstract uotd dwt); J Differences between Alostact closs and toberface? ____ Awstract class Pnterface * Abstract class can abstroell -Drterface can have only and non- abstract methods abstract methods » since Java 3, tb can have defautt and static methods also * Abstract class doesn't * Pnterfoce suppore multéple Support multiple tnheniton| inheritance Ce. + Abstyact clase can have }-Dnterface has only stotte Rinals non-Linal, static | and final vortobles and non -stotte vasiables * Abstract can provide tne |" SHerface cant’ provide implementation of interfo implementocktory of alstroct| ce. class. s-the abstract keyword the Interface keyusord ig is used +o declove used +o declave interfate abstract class + Erarnple+ » Bvamplet public interfoce Ovawalle void drawl); t Find *Pinat is che Keyword | and aceess moditees ulhiclh és used -to apply sestrictio On a class , method lO Ntorcables "Penal keyword és used wotth the classes methads and vorialoles *Ginat method ts execerted onty when uve cott LE * once declared, ftnal Vortables becomes constan ond can't be madifted * Pinal method cannot be overridden oy suloclose Binal class cannot be innevited Oferences betuveern finat and Finally keyuoords Pinatty * Fénatty ts -the block tn java exception handting is -to executed —the tropertant Cede whether he exceptton occurs lor) not: *Pénatty block és atesoys belated to the try and cates block tn exttepkton handling Penalty plock ts executed as Soon as the try & cotth block ts execited-. *-Rtoalty tock suns -he tmportarrt code een tf exception occas Coy) not * Pinatty block clean up at\ -he vesources used in *7y block. defined packages C2) i AS Ho w -ko creo: ! +e and Jouve explain 9. use user {Us a | User defined packages* d by -the user: |The packages ave define To create a user defined package steps to be i-foltowed- & Create a packag syntax: package a Deftre @ pacwag? athe of declare th as a pur guodireckOry cunder e act the begtatog of -the Cele pacteage Nanne: class thot put tn a package tic. 3 Create O the derectory el) Ye raatn source” | “une Listing OS o class name - thts joo Ar Store file ts eveoted in O gubodivectory 5’ Compile the file thts closs “Qile ts created to suioadrvectory Eno ple program package P15 public closs A int ay void mC) System: out: printlnC dood morning") 4 j Ovtpot* good morning - en java: ae llvite a sh ote on & mn s ( ove note on excepeco' handling { | Exception hand ling* Inthe except ing in | weehaet hondting in java is one of the povoerfal i nian -to handle the suntinne so that 10 Se ronal form of appilicatton can be roaintained Htathat ts exception Exeeptton is an event te distrapts HO ae is a0 object ulhic of a program eosaoss e normal forre h 2s ¢hvov2? ot pun-kime+ Advontoge_of exceplion: Line cove advantage of exception handteng is tO normol kerre ok a progvan: exception, go appilicovor ee ma.tntato aistrupts the poral form © Wing we use exteprier handling * alle class except won as Rurrtimne: checked exception > cQe enceprtor le -time- eg SQ eotceptton checked o£ compt cheeked excepttorn are Leon tg known! Uhehecked Secepen § ses shot extend puntime excep as urehecked exceptton es tion ef¢- -4 + Awe . _—___——- le %& vitmedic exception , atullpoioter C%CEP ; Nehecked exteptton are not checked ot compile #me | Bother they ave checked at atuntime: | hs aaa | stor exception + | Lavo tS ivsecolesable eg: wietual rnachine essor Asseseton es ton Out of memory ervov 3 a . A] Hows +o create and woise user defined exceptions tn | Jevas | User defined exteplions + jz you ave creating youy oun exceplrong is known jas custom exceptton ton user defined exception . “Youa custom exception ave used +6 creat ‘your oon exeeption ocoording -to a user need. ley the help of Joura, eustom exception we can create j | eur Ovon exception. | Example program’. class myBxceplion extends txception t | Stving stvts | Myeaception (Sering stn) | | | | | Styt> Sty25 $ public Skring ~tostrtag C) 38 eau (MN MY Baeepkton occured +" SEU, | % class Dero | i AVY 4 Systermout: printtn (“starting of tine lock ")s -Unvous new My ticept on (ris ts rng essov message") % % ge) Cortech My exception exp’) Systern out princtn (i cortclo pokes suystern oud prtnelo fexe) Ovepud! saorking oF ne tolock + corel locke My exception oceurved thts ts mY exsos rnessage- thot ts a Constructo 4 aplatn Con we jovad, Constructo’ A constsuctoy ts ao special merabex -Cunckton used cov automatte initialiSation Of O°? object: obruckor overs\eadting] Whe cons MEVEY an object ts eveated the constructor Catted auctor atreatty: Constructor querlooding + Ty java, th ts posstble | | class constructor that shove 3 are 3 he samme name 123 Pavameters dectaratron' jeatted constructor ovesloodlt nq: | | Example program. | class p | xtotd mCfota) Systern cout: printlo Cea 4") votd me) systenn rout: printls (sgava");, public static yotd matn (stveng argsey) P obj =new pods obs mes; Ole: Objem eras, 3 +o define -kuwwo lov) more as long diftfevent hts ts at ova.

You might also like