Shubhangi Bhatia 19570050 Java Assignment PDF

You might also like

Download as pdf
Download as pdf
You are on page 1of 9
Soe fnnbuzeyuZe b<>< Qt What ts tre purpose & an abstract clacs ? Ube Hae vestictibns applicable on att abstract — Qe Class . A dass wmich & declared with we abstract word 1s unser as Abstract elacs. Le fs maccty used 40 provide a bate Sy cubdascet ty exteud and implumuat the abstrack wattwods aud ovemide or use tne Tumplamented wullode i Qbstratk class Ruts fr abshack classes ave t 4 Tk weeds 4o be extended And fe wettrod uplomonied. De cannot bbe fustourioked. d I a chars Kae eenr ove Abs hack mellred, dawn fig dass at be an dbthak dats. 3: Awy Sub caw extawding fom aim Abstract das should Cither imploment all Ure Alabract omtrods of the gupwrclass or tne sub dae ‘kell shoud be worked af abshach. A 8a clive reasons as 49 why walk wmtlied 18 delined as Static. (0 2 ~ 4 ace tue mol wutthod fs static, Java Virtual ee Modaiue com call withoub creating amy : futamce of a Lose WIA coMbalat the vaalir | wwod 2 Molin wetliod ts wmode ctatle bueauce aw Objeet te snob required bw all a stodic welrod. TE te wore wouctatic. , IVM crutee object ree ond Haun auc tee main welwod Ue Uads 0 te proba & exba wumory allocation 3B Th Mol wetucd Were wat dectaved Stans, Hun IVN har 4 ereate income of Main Oost Ovi Chuce costructor cam be overloaded ond (Om howe Arowmurte, Hume would not “— be amy curtain awd cemefctent uso for TM "SG to find woln method in Java ° ———_—_—_—_—____—_ 83: Difevertiate betwen tne foltouchag aud se exanaplet inn toes cose: | a) A ay Laken and ty Rosa blow. TRY CATCH BLOUK i 1 —— This. block i exeurad ony # Here is aun ey unhandled exception amd the Geeta ue ove or is subdas tthe one eputhied mba ach block's parametor, Gxomple * Public clare MyClass F / publc statue void main (sheng ast E ay f intl] mph ted Systera ok printin Cony nlurn C103) 5 j Cakon (Exception &) Systern cue privtin Smelting cont corerg )? j 1 : Sone want wrong TRY FINALLY lou + Firotly will always be exeeubed alter try Oud ALOK blokes yotelher aun exception &% roused or nob Example * pubic class Tate Finaty § posue Seotre void ici ala) age Q fF hy € int datas 26/0 5 PN System out -printtul dasa) % cabo. (AvitteamodicExcep tron e) é System out -privia Ce) i J Fivadly LS ystom out pret ("fi hou 1s ceed") 5 System ou priv CYvet Fine code “35 Ouipur + / by zevo Sinaduy boule 18 abuso exeuted you the code Wate ©) Method overtoadiug oud wetiod overnding Martrod 0) herieedling 4 Te process é detiving fumetions aviv te same mame Wills dierent pararnth list is called wetnod ateeneclt ' a. Je te a velobiovemp becween wilode au ume clase go De Na etosie. ruling Cox cowie time) 4. Return ups do wet feet ounieadivg 5 We via ie oily be cleewved during tae \nhoutauce Melied Ouerrfaliug When msthods & the Subclass basing we name 4 that 4 cup chose, overfden metreds —_-— SU & us superetase, it 1s method owwvidivg De ig velattonship burveen subclass mitra Quad superclass, WV muaktrod te & Syramic Qeensein binding (ok runtime), Am eat mi Mawes awd Squnianrte Ss fw tote overridden cuethok qyuct be idomica De chswwed / Cr su fubevitance QA: Cyan eee following nferarcny & choses = class A\pho. £ Clan Beta extends Mpha f clas Gavaa extends Beta § =| Jn what srdev are He coustuctors called | woe at sik @ ‘Cavan’ is evented 7 Te constructor will be called th the Flowing edu: 2 L- Alpho Beto Cr 3- Gamma 05: Create a usew lefvreol exception class Mytxeeption aud use this class to Hava an — cnrer condition ‘ft the wurnbor is wagavine. SP WAP 40 conmpul the equave vay ba “oO using usur debined mutrod MysqrtC) whiels raises exceptlout # type deception for 7 7 = a nuwrbers ‘maport fave. utll Scanner 5 5 e—_—_——_ loss Mybeoepiton. wxtevds Exception i pubtie Myéxuprion ( String Ds —~__ /—— Super ct) 5 5 SE i pubue class MySqvt = void Squave Cint 1) throws MyBxceptiong -— tT LKOE Ahrow new Myfxceputon C Nps “A __ number onttred")} "QY . 4 else § Op double temp 5 double $= 1/23 do £ —_ temp = sj Go S= (bump + Ci/ temp) A ; } woud (Ctemp -£1 = 095 = System out: printtnl' Square root A the mumber entered is 2 s)5 4 f= pubic stake void mai orgs cae v Scanner se = new Scanner CSystern inn); Nysgyt 5 = new MyStyt Dj Systam Out: pratt C" Enter a. pocitive number’) 0D) mun: « ites « postive ste WS] tee oquare root oc the mamer encared ss: 2.0 yj) pap soceseruz fecent tine: 2 seconds) if Enter a positive number 7 ‘The square root of the number entered is BUILD SUCCESSFUL (corsi time: 3 seconds) 2.6487518110645507 Caught the excerion Wagative number envered BUILD SUCCESSFUL (cotal time: 2 seconds) tnt a = see next Dnt (15 ee | é Sq: Squave (a)> 4 cok, CMyExteption «df Syston ouk printin(” Gough Hae. exteption ">; System out println Ce: gor bessege oO); | 2 7a, ~S o S

You might also like