0% found this document useful (0 votes)
22 views24 pages

Java Upto Day 13

Uploaded by

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

Java Upto Day 13

Uploaded by

prajakta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

A

ModiErers iD Java.s i

: Public
2Dbvate t

SFim
6 Synchroniae o
Volale i n
5(ri 9302/e

1) Pbtra

Pceess modieeE}: \(i 20


elocdheo use3hdddiuse addelS oUtie

ivOe

KPuusl1G
eept CODsuto U e mRm ber oF
Su pet coug so betlSofo Sub eajg.

AYpes o TnhetifaDe e
Tn taee Enneu Fetna e
intezoo e
n terdoce B eteroig

Dvn in hej toNae 15upe pe sub ype


nteefao ther S cal Ro040RAee ohei a
Dertlnahetitesde Aetes4ppsup2
Jeleler4 gingie-subifEHtPAiHLAis
letee ogteiAteEPeee.j
Muliple Toterface Tnhetitooce.
DcunginheiteNce if there e MU Hple
Supek iotelaces sngle sub iotezkace then
i t is caled Mustipe jotezlace inheutance.

iDtezpace A

s0tezfa ce C entends A, B23


MuHeR Toterfece Zohetuhace
Hierosehica Zntee Poce zoheiranre
Duein iohezi tanee, f tnee s 3ing1e
Superj0teceage mudidesub otefece
hen fEis çaWed hierazehiCod imccfate
nhe tanLE
interDeoe
inteyPaee G ecfenala AZ3
ihAez Eo c e eextend A r e
n 1Hiegaeahicol otetlaee inheg, tae

naltile iej intezlace Ppheitanee


Duing io heajtonce, if sing1e iotezRce nhesílone
S hasingmuH ple, leuely then jtfs catles
Aim ileveliotezla oeioheuto a
iniezfoee c ektenolai:02
1mHleue)i0iezPeee johezitoDee

LDplemantetioD Jnbezltaoae
DOEnq 1oneriteonee ie supe HPe Sub
ype s aials dhen iie jsCald nple
Dtahoo io bettunee1

Closg A
clols

7eraee

Tote Derce B
miUip mltipe Fntezlace nhakiken
singl jnezlaoe oheLita DR v

ToteePace
Toegaee
Toe ce /
EnierAeaa e e LEMerPaae
HietawhicalinZatezlaae joheirante nes eoe
Tohe anee

avg mukielod o hesnce is not oilau-e


cn 0he usordsiclas caoeelseno d one
Supez Clo4 Cahgaau candee N.
Duioginheitenre e mber Gper la
dndr

onetit ino uub alo5 Hene


cl netaneR ecan e e3S men ugjngoub
SUper elau cLecLDe o bera
sub
D i nq jnhe e iene e, memberg elg
o ub
lo no clae
nhesd inNo supe clus
super leksinsdence c0e canocheneeung
ORRS
A Sure clas On rOm ber.
**ea

member supe cless inhet inta


chas hence oe dan COnsiolel 3ub alous Sub
ingtance e super
S)nee e Car) comidaloASnSne e
Sub clas inance
C SupeA ClaS inso
Nee, we Cu0 us e
place af Super lodiis
Dernta ns2anere.
Coneider Alosol oglcode lso
Emploe eM e lcDu 1 ok
Eoploye emP2 neuo Employee O1l0k

petsoD Pa :neD e s0n C

Gmpo ee emP neo Gmployee c


ers00 P1 emp3o 0pcoukhinD9
Pcrson P2 ne Employee C c)

embers neA Bub alaJs da not ionelt into supe


a s hence we CanotrConsideSupet elaus
instonee aj a sub cass n3noe
C Cuery Detborn no a em ployeR
3 h o e , 3uper dass insia neeCan noF pe ¢oMden
USub clds 040Nee» 0 e OO NO
ww.mi
use it
oplace aA ub claS InsaDee

pca 0qt
rcesso Acouehog r0HLaNee oL suh
olosntoefezenge oA upeE lagS
Called pcaHng
Campte
clae bose 23
Cla Deriued acteol3:buse

pLb 1c uic Uoid majo C S¢ódg e oeg3) 2


Des ueadetueol e peO DeLived C
dav ed d/spla eiard(0
Dose- bats CBose2 dalveo 0Peali na
pose bose cdeiiveoAUpeapin dlso ok
bes eghodaeag

Z othet ugrds,supe lais aekezana2 Ca Cof


erenCe otsub las i0a0e ZH Fs coul

uyepese ORUO Dedsred C) 1.upcasi0qa


Tn CoueoU pdaLjOqugnq supet eoss aeféran
Ueriable eCan adaes Pedla aA, Supek Clo&s
ON
M fos cAO1e

bey C hse e ) Derivec) (j#7upea4/Du'


3510r).Out.mnen
Num bosc MuM2)3 o
C'Nu 1:hape, nurm)

ii soenaa

retezeoee oiobie lu aono a0egg


9ub eley epeajfic_meinods hsoh n o
no avadle b1o D supea elas
23 enna

To Cose of upcaJiog, ssng Fo sub ag


d034anee saper ols ekeELNa e Uialb 1e
C acOR3S Oly, RmNeR Supet a .
TH iS algo eoUeo cbjet slicing
upe ayH 09: help us tosealuae masnfasDanee oA
m

hR appicatiOD 9191 coE

Lelo-u in+oeRDoeo SUb cles iS calJed


olo0ncos ing
o case olocoocojnqempiolt do0nauir

mehod vexediog
praceis ot edehnid mesthoo a supet cJevg3
e

nside gub lag S caslJeo methgo QveLsiodDg.


Dyromic metoo olispeb
roceg OA Cal09 mchod Subcdon
30goredetAne of euper alg 1S CaUeal
dynamic metbad dispaseb

L cemo UPCoUi0g ius0q 3upez claag


Ocezenee ciaeue
1 Bields of supee clous pheyt iao subc ay
2 . hehod gAisupez oss inheikeal ihlo subtl.s
Ovezidenmethed e Scbela/3
T o ca a upcoring. us|01supe clos
0eerenee uoruable, Ue a nno alu s

2 NonOuerelden mehod:ofeub alassi


To ths Cocetoe neel to doidoon CagH
i0staneeo f s an opetato cade of upcostin
ies Usedto cheok,ohetheisupetnelS clera
ongq relerene e oMo 3ub S ngtunt

Jova1onaObjeot :Suhec elak


Sub
clos youa.log Shinq Jauou H Dae le Sub

1 Sn 3rl- neLO Shipg (lOR


Obet obia DeD StooqC u p GayHoq
3hdoq_3ta2 pe0 Obj lok dou00coyiog
2Dae dH:neud Deue)na 2
obea OA neuo Dalec) o upcug
Date dt2 Ooe) b5 k Dom cai oq.
) object 0bjnutljLA3Se
gna srCsDq abj ok hos
Dale dade Cbae1
objso Concokhnattud
DOiCatin: lu
w Cbecobj eO Dede C
pt d COeobDom caying-wo
Sin CSSng) obj Poonrah-cledsca Czrepie-
dooOcaioq Pails , theo Jvn hows classcatbxepti
Pues A mehad overidina:si
oniben
Subelas oUeride3 mekhod of
Pccess mecueie i sub daAS memodSuper cleesS
So me or it sbodd be wider ha upetshoud be
mchod closs
2 Pero upe jo sub closs ekhod
ov it sheulo be Sub pe n showd be seme
Shou be covOi gN
othet uords t
Mehod noe, number of_poiameky 4 hpe o
pezameer
Subdus mChod mo44 be some
4checke -xcepHon lis~ in sub eloug mehoc
srousd be same or jt shaulo be sub Set
Ushnq aboue les if oSe raline meMad in Sub
clas theniitíS.casedmehod avezidling
We conmoB ouetidA Follocoin9 merhod3 in sub clas.
Pucle raehad doia h sh
2 fipeu mehd
34aHC Method.
OUeride onotatioo Pomarakson Tyee K

Cvetjo is Amotation dealeti0avo, lanq


e

lapec hec deende othe r


genemse meieta/ cdasa 0d
dan) /ordee..Compile
mehodaueehidi
t o e dorok Sollocouleiof
w e use oueLAIde annoteasioDthen joua
Compier qenetcet eAEOT

XFipalMehedi- imptement.
ACOvinq to clienss equs rement, 1
fon oA Supe. cles me/nag ilogicaA 100/
Campieke heowe show alealo2ei supe CHES
9
mehod nalk ln
N Can No dvezejde, Ana mehod overede
Cned inehod 1nheeitNO Subolauk hEnLe e on
used tdw }ngunee: o# isuhdlauss
besacte methoolsn
Acoroing o cUeAF3 ueenk , ie impemcotit.
on f upe olos me/hoe (salogicy 10o7.
incompete heo iwe sbouldi d2alatt e Super clg
mcihodahgha@t
ite
Abaaci9 eq (Ogrid insava si
we con0ot mDioke Dod tah ahga mthod
Aeyhod ofa alas tOhich ie hauina a body is
Calsed o onuKtenehodCIC Lnon 3tha)
A metbu of.adas 00 bichs not havinqa bed
is Calvd o abehact methad nisi
T we declone MehodabasuF tHen t we muH dceler
closs abeha eh
T mordaton to aveiLide akshes menoel in gubud
othelo Ise sub clos Conafder abga olasg&.
lelSmgyuy n be.CoITLiO abhed mCnad.
tfeiopiemeriahioo 0f ahgaues lors is logicef
ncamplek e CoD. Do nSeanioseit
ca0 CreauR I e L e n c e t .
wp
Gtamo/e
Jaua lang Nuober we ath
n-aya lang Cnum
aua UH Clend h
u dava. CLH. DicHon

T m'emenkaHon of a slavssogi cy1oo comlee


Hen e deolsR uab,Clans Hna
we con.1nstasioeAnoJ Ola bue0e danrof enS nd

JSaua long 3ykemi Osid t


Jaua1gnq maA
PICwuppe alexc,ari9 t i
. 1ava largiSig Shong Bu DHex | Shonbuild
auauhuHI. ScaDDCe in bin
1
ue.caro ueabShad 14 NaJceqword Fogethe.
Obieo dols biev d
objeais noo nou 4 ConcaeR OS hich 9
aederal D jova . long pada1 e
ava ong objea is.tlmoe bose elos/S uner Cosgn
puge clis oto t Tava aloJS bieraEah Z0ha
wo, al ne aladse CneA oterPo ce o djatoHy
O D dURAy entenos Om jova, oanq
b9olok
oenplementeol 00toterlace,
d o exend Conda)o neyeed ype CD e Haee
clors entumLionnaldio )
doekot contt):nysield
JCoNeyOSON peramele Jels coDÝuCtOYr
Cacuny delaet A it
Java
Objea O neus abjrctG D

TConkung metodsCS nenADalt 4E9al rC


olluc09 e afjaudlan
noo Pinal menads aF jaudan,
Pu5ic Srng oshanqic fosh S
2 PublK boleon egosiCobeat obj
a9Petblic n basbCade co S
Poeool Objea lon e Chr0003 Clone NotSopper
Ceephon
Lvotee vod Pinali 2 C) beong 7on0uDable

Folloeo) ng ote B0aJ me hodQ:ojato alarq.Obegh


6. PubGAina CloJs 4rac clale
,
e,
Public na Uoid dat CD-dbro cag ThteetUphrd Gc.
at lonq Hmeout) l
dade
eeineepmp.*
Clong hoRQuE1 Nand)
loQubllc yae HO vGid noity
1iubliC Ai0a uaidOo y NC9
SolR Constacdo
constu ator Supeidasthb s design to
a oro Consu o r o Sub aloy s aauleo
G0lei Construatar 2
oshin s noDApalnon Doive
nekhod o4
Obeot claess joyor laa

puubligb3ngFSmng c
USE gn unth

6mployeeenmP peo Eoployee 1

enqfoma en we should use toing mehoo.


ZA UDealons defne oSng meheol nsice clos
hen jts super vcostoShing inhod gs Cajed
Cons1ole s0ukce code of to 3m ng mEh od Aom
Objeat class
ackrnadtClosSCA, get Nome) + ' " +ateget.
ht o 93 gisoeeSng hosheaode cD-
t Shng mertod koroayglObjeetreleos 0 Sing
CoDiSt0g o the nameaf the clas a cohich
the obe s an 10onae e as siqm ohero
@4 Hhe Ungianeol hexonle cima e pae2enFatio
at toe bash cocle a the objeat
Tn Shot,to eng mchooloA okjeot oors cuens
ShingiD Allooio Poernouga) seb t
Pul Quitiaeee dlo ame rto&bende.
accoeli na olenAeqoemenu mpemaneAON
o Super Clens menod is pariauyeomplee en ase
Shouleoveeriee nerboo etosub elass
pub)ic ic Shong oShngc2
ehp this Oame hs emd thdept 41
The etelt jo oStia melhed shoudDe a oe
u i nfarmal4ve dhab is eo3 0 aCod.
Par;0 peL30D 40, 2oo.
bver tide
pubic shioq tashdmt)
rECen 3ong fromd C"203/ darla.20"
hisnacme thiSempidi.h aar)

saec cen-erded ithedn al su beJosse OVe2tuoe


toSnqd)method

J 9 e uand to compeE e vetlue Seute a NOicb'e af Ual


Eype hen uoe houta useoperowoY

Dum)1o
Du ma 10
Ou)iT=0um2i
Tajavet iohtive p e oe oot clsel, rlenee
we an Dot u93i eguals mehodhoo9pe

We CaO u9e pezaUavse Valaae adinehazeNe


pe.
T uge opezaoNle co Votabe, af cIfaen
Hye iE olaes'ns Compor 3hae oinsaneeoather
i t Cor2pores Staen e/eregerVCuable
TA e uanN to aOmpa SUea ngia ne theD w
Gheuel ue eguals mehod i n h ta
equa is non Cna 4noO: nesiue Metnod a
ava la ng. beat odais ,
Synde
pubic boalean eqtals objelh obl J
o e dond olesine eotlg mcfned 04,E elag her
K Supr clos 'S Co ual mehod gek coaleo
ler Code of eqyel3 rMethoo of objeot elesS;
C o s o e r

owblic booleoo
PLblic
u a l g C Objeat obj )
o e l n C#his = objj3
eguals menod 04 0bjea cleis do nof c OMpr-
aare of ins/ance. Tt ComDor 3 k e of ocleretne
aclereDe
T e e0ond ro CompOt e 0Side mefhu, 3kte A
instonatocg ieDoe houa oueAjd eyyals
mehod o sub clods.
cle Employte 20lot
ovote smnq nomes
Dvohe iempto Dsta

publicCnploy.e
public Chi ioe,;n empidlao
his. name hame
sedery
1ao
hisempid empid s08 2 2 A

puuslie Doplean equals C0beat obj)


( o b bi nuJ hia
EmploAei otheti: cempoyreJ nobj i
5 Chis empid otha: empid)

3
3
PLblic dlolk_poorims

Gmplege Cmpt ne m plote eCisundee", 3 2a


Enployee emp neoGoplajre CSundep" 39, <*doo
empi yuels oemoa? )
Sem Out pointin c"nual
elae

p @quala.

Ceeption HandaDg
Renaese ype 4Scouce
uoela srble is lnteztaoR denastrdiinjaU4, lang
paakrae.
voidelose c tmoS cepion isa meknod

.
Closa.ble is inlezlaoe dedlored in O 0 packe
e

v a i d olose c) thOwS oGephoo"isalmebo


c.loSebe i0terfag R
Considez Potloohn9 Code
l clats Tes is asoerere iNeR
Cla1s T e tmplemenk Putoease hble
pLLbliG Teste

Oveztide

Public clas ProgauM


pileiC khG voio meD CShm C1 args)
Test b nCw 3 C

L/ heto Fe gCJj2 nsonce 2e2aU20e


T n to
Cl0kale Oveae inieY
OLmCytf AitocløsenblA O
49pe p e 1 s 03rDreis alleol
sCaled e
s . C c l l e d

Erodi ngysem ae0uoeg P youe aplicas00


enNoay OvD conhyo)
head

Socre 5
Cop00hoO3

S o dewice in C

Oneroing 9 eND reouèe o e i m i feo hence


e9how d uG 1 Ca-eleiuy Z coe ans to
hondle t Coce Aul eo 0ei shoul us eMEephof
Lhandd

What S aepHon
Ruphme eizoss coed eO EAiODog0
Goreepoo is an nsteinepHhat fs Use to send
NohacHoD_ta thes ende uuePoh h Sy4em
E an eepiona SruHON 0Co US n the

A Ho o hondle ercoephon :
Using tlocahn Veyio u e Cato uAaterecce
:T
Cucteh

4-roD
Hnol
L OUwable is ela)5 clea ed io 10u face
he tha0u0b1e is superclai3 o o ez2o
oLdepoD i tnehaug 1a0guogK
CihguUahie
esn

abtat tnar o e Inmonte ot AS C l s r


he m
68 Can be brodn byiet h e o a thooca saier

Similarly, only his clal3 oTone of iB JUbag-


Can be he ovequmen Hpe o a ddvch claUse

Conssuotos o ouoab1 elal:


publiGTrowalo e C)

TNoole Eheu ThrouOa ble I

2 PubiC ThrowableCSmpa message

Thhocoable si Den Thoôobfe ('mesgege


AbcThitocoalke (Thodabr cauka);
Tmowalse aause cDeD Tha@dae"nelas
Trrouaube b) e Deu Throcoable (cause )
4-Publici ThrocoabieCShing meigèae;Tmoecolre'caune
Throtoable CaUge peLo Hhraedah1e )
Throroable E neuo Trouahle C"mesege', ause)
CT

D
ENeCep-1a0
Cheob2 Cxeeption
naheolee Bxcentiopt
Deigned for 3aua cope
Unebkcol BcoephioD e cin ale. ro 3 N

clo yr)
Jue lo ng: tnhme (neioD 4a S 36clae
Ketonsidez a unaheouo ercoeion
J snot medlotery ro hanalte Upcheokeol theps
toam plel
NUoberfoamou neDHon
2-ClowsLaGxo
Nuu
epHoD
3 Pointe Cocepion ann
4Psayfrden Our6f DDUnds (pcaep-io D 2

ree

0va lanq. GeoepHon 4 td 4ub alaS Croepa


em
Jdua lang:2yohme GcopoN41 Su akas0)
Considet ed e cbeaaed aaepian
ampe,
1.Clone NoA Supporte Geeptionn2
CloSNo Pound Geoeptio r h
2 eLTupled GeepHOD 3 tb
uTOte ep4Hon

THSa veyuoOrd n JaUa

ndpeHOD ghepeDEghoulójtehrBloak/handle
y bluc mu ha veicHenItdone coth b?oce

Caleh:
S a heIOSd D ava
A we wans io handle ecephoD hen wesboud us
wch block c caleh honal le
loce nau haye muliple coeb b10ck
ry6rySloce
wtCaehablocla hand1e mukiple specifHc
ovtc0ioO insidesing1e Caeh b1oc
considRe toItoca n4Co de t
w

htUPorverGtecojoD ex
w
neu NuuPoinkee (atocio0 C) 0k
ohme aceptionecL DeLONuwfoinkee G<eemind ds OA
i

ne
ce oD fe neioNu porre erion (2) (souaned
0PCOk A

GreepHoo clotd elteeeveiob/e ca coawn


eteence of Che ceea ueu ay unheateal 2AOeN ig
Hecce o cori ejeneic Caley bloak oe 3houwd use
hosa 1an Gce epon.

Lah C ceep Hoo 60 generic cakb blocks

THISa reyword io jauCI ti i hap


Eoje va O pplicouioD2Vmmognomee CaL genetae
Gseptio0 T qenerat CzeMiOD TP 0se ghoud e
hnou beword
ONyobeok hed or eindtoneR o hoodabte
Clolsia one f is:subolagsèJ12 eerthmousD

hooo atemen i jump S/akemen


e

Pinalu
Sq atwod n jaua . i P
e houwdusA Pimptly:bloc a iO
boc may hav e mulhpt12 Coukeh b/oCk but
but fe
CoO CoDeso r y ooe inol bloC

coShçs0 e
Gry Seione 9 Deo Scanne CSygiem 1 99,) 3

e mAtSaaK Tyu e c n

thou3
S a ceoJOdD ava.

6nR mdhu to anOre methed rey we ghoutd

Ze vncnod bmous unaheokao Rcoepan heD


hanouing eaeepafenSoHoO
T me thed toeos cheaeea ekoepiOn FHei
handlnq is S Mandao b u
Bieepion tanding oen T GG

CuStom Usets peneo .cepo0


vm con no ondetuno r EpHoNcu Ons HoDs
Pu'sne 1ojc euanto hunm lel then we
9heuwal aleine e deHoe eO EPHOD1clasS
C0Bom upobeaked excepioo loss

clad StceOuerA6co xi epior Cero PanHneGAephon)


0
Cuslom checked acep Hon cloS

@aJS Stockdua MoocegtoD Goeok LceEpion

Sack
Sack is a ioea dat auekae lcolleaHoo 9 LOich, ue
Can 8ore elemeAs 0 La Zo First ous maoee (LTFoJ
-wecan pe:pom follocorng eperaion3 onSack
booeao empty C j0d ex -
boo lea0 fuul C)jA indeatsae -1
oio pusb INFelemeAtYTo jnser ole met
An o peekc hTo.lead popnostentmenEDNhna
Uoid PopI; To emoue elemeAf ,i qD n

Aoeptio0 chauning mnssumN


LOe co aoolle eAcephioD:bltOiia Rw Hjec ok
e cpioo Zt is cadJed osICxaepdon chainino
Tobe Con teat of eccep-ion haneuing han
u
2-cee nan

ZA ime ertariCene ahed oluedo deueloperS


YOstae e hen it s cosidezed abuq javg
PPiufo NalihA 20ipbao i
may Tade Ot of ounds(puepho0
horHe t
tO 3bowa not 0se 67y cakb block to

2oceepho)
A nHtoe 2 l o cHek, geeraked due do end uie
LCNe mistaR heD it is Cogde?-o aj edeph

Ceample, .CaLotFoc GxephoD *

PleNoh found xoepitan'


ue o ul hyeu bluckito honadfe eceMan
hrr

ZA unHme eR20B gek qeneTOLd due to erUence-


Conoll Hong hen l i s icaMd ed a) cztpin
osa a ppicusioe prE
Gonple 1 OwotmeMoGo
2 StookOvezloo Grorioip Goig
, Fnketnal GoVs ced
recomOD Ndeo Jo wse yckkkh block r
henalle e r o a i
Funcon Pchuaioo PeCore CPAR1
Program 3oecdeCHo o iS Caeo prCelsIaonoq
ngtanoe d prograM js CaUeo aceR.
mankelins 3aak per teead dhis suc
40Deug gadkome
StaS ha ame Co pal 03 daa o Catled AineMoD
. ReteD Adhes.
ehooPameEr g,
aMesnod Co da Uoriah1e
othez eHhod Cals.
. emP space o ComPH0g.
Thisinoxmosion oatd ide siaok hone is
Calle Pare adHvatiod ECoro

You might also like