0% found this document useful (0 votes)
26 views16 pages

Java Unit-2 Mca Pyq

Uploaded by

sushain16kaushal
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)
26 views16 pages

Java Unit-2 Mca Pyq

Uploaded by

sushain16kaushal
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/ 16

Unit -2 Date

tommand pemþtusing nt ojace 9


rva,he clorpath is a'sPasa mcBeu that 4lli
the Taua Listual Hachine (TA) and JaycL Combilky
ahexeda aak fax usedefined-classer ahd gockg,
Bhen aunning.
the dizectone and /or JA es thafontaín the

The de autE dalse of the clast path i


that he tuneat directoy is dcaichedl.mtanig
The pufoved
using Hhe -cp
tng the clat path y
tominara ine Stotch This aless
the cAssPATH +e be oiet indiiduolly dor eoch
ablicadtan uithout of'ecktag otheu
othen abalieatioas
Rale
Jhen ambiling ar
Aunaing a Jaua abhlieo ion, he Hoede

aat coakoa yous Jhua code and aay brasies


cedere
lnsgaths) into.cacs Jaua
u)tacdaud the yeut
thecally
C¦assNetfcundxcption"c'NeClast
The DefFoardEru )
cga braiTDehtnclery
peut Jaa aficadton
~cmaically
indaded includee mming, Canv
check: standacl
dont Librayies \lotÉeen.
ies. lood othe ccpoh
chtue tht debenanHheeRezcatc
nerd the Ihigclast seie
tlatipath library
o
Jaun (lasses
i alo The.
speug the i-
S+anda:d Bydunamically cla:cpath
TUH hun
dealt,theJu Can fer Jo
this ssogmt
you sue¯lve
erthle Dole
be uuillhou
houe loadedat_needa.
In
libras1y peeifie
dunng
GndLlaet
muible he found e4en
classpath modularuntimt. hese
(ca names
cny n
.Dxecories
classgoth..
he
tanmand
)tliag Hial4thieoeatoct
Caleni
Stmieclcns
u clacspeuth
can 23
Ci]ûn
claepath
ded :con
ne C)
erte othe 3) Contaioing
when nix-baced cninte Lintain
clastpaih
cuneatsiunning cthe idoct. 3
tia tompiled
synt tiath
seuton.
temp2oray Fege
cxCompngnd
compiinya can 3
ke cla:s
inux:nd be
aahe Eseonpt dtharakdb les.

i nocl
You Examblei jauac
ians
Sessine Setlig
con

det the fowac path


p
the
IASSTATH tyexclaises
cp
CLAss?ATH
Ca\gclamecjci,nylbeg
aiironacat
enironmat
i/pathkagjoxn Dato
4Qubhanh Pago

Wouichle
waiable
Lommons
SikeEaihi, Hent
aNoclasDe ensurethe s Quoidisues Thi
uithithe
aAe clacspath tig Commnon Jndegvated
the cSasspataAhe
case-
Shelled geatually
lase to Tntellig
sieqired' ue Tcués uith
den ond
siueon and uct Peuelcpmtnt
Check more
geient gcor enionmeat
formated. Related DEA,and
laserQHeyour us
inuk This -
at
clas20th to EnuirGnrntnts Ccte
compile euC duthish,
Page
aaa
Remembo! èadyandhel
Wang
Qccessible. Claapath eani
mocb indicales blea
tione a
etings
that l
hut
patht DE)
au
tshat and
S Lt) Elboae Re
3 3)4) Absoct Loneete
close that
ahchact a
Ceeün beinstadiaded
auhoches Qchieved
bshact
embes1s
txact non YoT what
Abatact gCrampte.
AbatCannt is esNes must modiie
method by is
alunys clasc metha: mecds
cass b chroungi Abahacdt
cláss a
smblemeded
close
Cueate oY
aHe-thct a cthen Cn dui
Cmethods
public mus auuaysblue2si(eescth cite class
ut can pmust
east
an Abstract
clase closses, CLOh
and
contanobËect ialemeat 9
and be be'deiiaed uthaud hy syndar
inheudd public and Hou
for
ficndye ub Ccde Date
othexclasaes, Rms is ii dubhashPago
abstract ation).
abstaat decigned
andfenciytmplementodian) abatsactio
one ia c
lases,co Lontaun
shod the An as ahaantg
al
closs. do
col okshocsinc
subclesid ioella n
be
a a)
inblemeilaion )_Abstct
)bstroct abstaion ablehent
Â
Usias tlass
cbstxad
ract Hhe clacc
abstadion
Indefaces anoAbshrac cancase all
23
esscntalfunttionaies
JnJauas not inhoit
Can abstract
con
uoid clacc achieued
delaileom both
coeHe classee
not an
sound i final
becau method
obstact
be
Ani Ihecemettod. un
l; nal ie tuso. andtadio.
heseRLouide the
they-con Cate
souide Cuthysh
Foge
waysi abtrat.abstaact class
stoct aar
H
1co-/. kon Qnd
ehod mustc
ue lass
obstracin bath
kxamhle
clas abshraet
'uord
Send
class arinol
inial
ssn Systemouinln
Das f
Cat
estencl Abstract
Sound
extenals

closs Longede
Anîmal
Animol ("
Thic
method
/
Date
anional _ubhash Pogo

is
sleeßi,

at muct
nentalons uhile
abstatt
hat Abstrct publte
had implement is Rale-
ee ollausing
untionali meant dogsound edadte
Tailicss closs of
ta
Abshoct uoid
aBcne them
ihe asQ
he
must
allaosara
lep1ento abshrackmethccs
to extencec
Ooutput:
main(Shing1
etacd basecloci
puâole Classin {locapt:
s,hileall b
by
in Pouideo
ueth dibclosea. i
- theix clea This qrg)
An Tabeitonce
tatont An ousndefinitcn defiad antnalieating Dog
byafabshroct
abshact ony he bou
in
cubelssre ke
subcla the cloce
clee
Page 10Gobhash .Fcgt_11 uthust
Dote
Jeaing cthtu nmethede ahtract to force cublatsg
cannot be
Aaal clacs i- Acass declaed a final

)ibrlaiesin ahett
A Suboas ot an obstrat claceSaheuit
and ucd inplemert allsts obchott methode Rubli, dotic hiaat cauble Pl 3.1919;

Cinal method i- A nethdedaued as fiaal comd


br be delored a ahstot tsclt be cuesidden by dubtlasee. h't fatuzt
Hhat he hehaioy o the methal fed anc
Cannct be alfeued by ciny Subtlass
Cxonble abstott assehicle
abstac yoid ctotEniae)

Jass Cau értends Wehicle

Systen Catpinta ("ox eogine satalinlhuichkc i- Lhtn a.uniableit dedaued at


Cinalyih alue cnianot be changcd ae
Pope_3gubhesh
Page 12 ubhash
Date
Date

anhenitance hati
Sustm. tud.prantin C'aunning, of cbjed
Jahesitance &s one f the key toncebds ubclast
Quinted Pcqnamming(O0), uhev Cne class(he and
ox childcla)acqutsee the pchesyt'es field:)cubcuclot
behaviers (methods)of anote das fhe
SY Qatient class)Thic alleunt doxCade ue usablkty
Cocl method oueudng
tiasc inalmethdDtnmó
oinhenitaate,bud
iaseit ufoortecl thuough ato.aes.

styucere
A(Rauent cas:

chtl al clocs B (Child iac


COucs A
Pago
Sydon. Poga

Dote 22

a) A

Hultieuel Laheutdone}-A dass_is Doto

clesiec a)tlt'ple Jahesadante (thucuçh Tatojaceu) -


Tava dosc not wapport ulihle snhouitonce
dihecdley ucugh lacces to aucid'anbiquty
Stsucune Hlowvo it an be achicued using iadoiacs.
A CTootat clos) Snloy intoyace A

intesjace B
Tntbyface Bmthost
llchildc lo cs g8

digle pent, tlac. Uass A


Ssndar closc A es a inheutance , typicolly a mmx f hieroxhtal
A (Foeat clas) auc mlple ahexiance JA aua, it an be ingenaul
A ucing ileace,
B C catld dasal akox Rdeace A

lcheld ceonss2
Dsheds yom)
Sydem. Cul. Oota
23

Page ubhash igce_17dothash


cass Cinpl antndt A,2 Dato

AB
Cate

t peliynophismnTouo. Throu_h iahetante,


kubtlos can be beal ccl a an in stante of ts area
clas,uhich alloui the vame methoc to behaue
dilseay dabercbng cn he chjeed had invskei il

utlhaut chnnging that douteco¥e.


existing tae fom eautn cldss, Child clacseh
Can ue alldhe mithode
anduoptstiec the por
intueosi class Anitmal
a) lethc bueunidingfor Elextbikty A
Can ivenicle nttccls dsoon the spatntsubeas
cloes to
Aexibiltyas a dabloss can Srcince oy change
bekautor
behauic uithoudiclgithe oeat clacd
3) bnhaned Hlaiotainability Changei mace-tp cass
the
sublassed. This mécuns you snay ned ts make
mcaificakions.
Tlaces.
Pogo 18. dubhash
Dato
Lete

kxblain hous goikaye are oclded anod their acueL


publxc clatt Jaheutancek xomple
Apackage in Thun i:a mtchansn for crganizing
clases nd tadegotes into nameacei, helitng to
qucah selaled type togthen and Gvotd name ofe.
detent
de.bavk Y, ocko ger ase czsentaly dieckantes Lehore Jav
'uessecide, ard the help ain odlo
more
egramnisy

4 The closec containcd in the packaget cf cthes


This.
pocgrang Can be msily scused.
s) In plckoges, closses coa be unigut compaeol
tusth-claes in ohe Packacu That tuo,
lace in daso
the ome name chlfuent hckoget can
can haue
Sudtm Dato

Page 0Qubhash
Data fege 21ubhssh

Fthes Acoroins pokageslossesom


to "hide
Qste meOint
us
Dcte

These atet- dtatd'ard psaualed by the aue

Toctage alic sucaude a iosses aindl inteifaces fo

Woméspact Hancaglintafsheq Ruasat iang


bchoten nant tíashes
) Acess oghali- Joua
by consoll hephckagei orauide
wisiaiy ef couciseest Psctechon
,mchadi,
3) ede Keusabilty lasses kat aIc eeiaked er
ackoga
Cormmany Ox Aithin tic gackase Thexe osue
Hheis monbex Con be accecsed 2
3) hlie a chs, mehod or
23

23
Duta

canbt acessed tuithtn -ht damt Cus Cuwn Tnkage unvals he faleuiny stepsi
patkoge ond
tarm pokoye packogenant,
he meon n Fubli.
cleclare
Jatkage s) Caeale a dubdirectog anden the dieckor cohe
filee ce stered.
Hhc
the maia sCexe
L) Stoxe the isting a dhe closs nanne.java ile sn the
Subdiedo (uested.
packaçe, aannol ortes
-

keorch then 1 clleuceel by a zackage namt A Jaua aystem


ThiCnust be the wlatem¬ud in e Jain dounce fileport tenm. parkoge cor be otteaed theugh the
The cinhor otemat can be Led to
Clos
foaltaye olecdandia
inhot qockagel. Ltgckaze'datoncj
Pete, packaqe is thename
Page
Doto
23

Pago ubhanh
icpe 2 S duthash
Tackage i, and se On we can
Dato
Dote

fave any nunber o aublik sdatc uoid aia (Shing C1 ug)


lasname the
txample coj-clhaplayfAD}
Siackaoe packagei;
publfeess ciaA
Rubli ucid displnyAC)

This uvte (le sheuld inteocee exanaple hethey Cne can trerd an iato

stoxedin subdiectoy
the benaatdallaccl
this taua file. Jhe Steslt ant package
java and
i: Nous (emple su youx
clasiA. clasi l beAn otedact bascally a kigd o
shasedin the igmf Subdircctey class. The
difuence
Classl nethods and tinat field Thit meani that indoyface,.
do not ecdy antode to wnemend theLe_metmcd
Qund data elds"coataia cny contani. koejovt
inport packagei. Llasths an inttfae to define'fhe tade dor aaltntntakun.
loss Tackage Test i
23

Pag
dubhash Pao 27dthssh
Dato

The yntax Qn
Dato

iassJhe Hulliple inhe:itantt 3 Acloss tan inplemed mltkle


dotocet, cuEICaming the initoien of aingle
oheitance in locses
intafae ndeutoxenhne No loashuctoxs s- Yeu Conac cutate chjet cf an intafac
Va ables declasiatoa}
ne thedr cleclaration . Puble by deault Al methcde in an intesace ase
qublic andl abehad by aadehulty and all teldt
aue Qublic,tat'e
Qubic, ard

Abstodion ate daces pMCdle tacy.


Thty allew you ts define asd of abstachtn
method: that
Q class mut implemiad, usi thout ditoting hoas the
state final methods wheuld be imkltmendecl. Tis altatas lexibse
songane an cin clefinig ontach behceen uaw'auc compontndi
&) Hutie Jaheuiance i- Tava eloes not duhport
ky Chauateuiskee ef Tatoufces muliple ahtante with claser (-to auatd anahigui
but a clast caninplenneut multileiten fact Ihit
Abstyact methods i Adl melhcck in on cinduo alloucs a class to ahet behauior uoni multple
houYces
akhocl by dejault, mtoning they cny kouethe
methe utgrad e ond no inpleentaon
Pago 2 dubhash
Doto

3 locs ouling By ustnq indotaccdy you can void rmethodBC),


dein a contt that Can benplemetca
cloce his makes cocle mnoT M
and nintainable,
aiiblementaeond
Chonged athcut atleatis client cocle
can be

u) standouoiaon,i- Jnteu dacesCoun be cec te


deine emmon bihavior dhat mulle classa
Can shne, pitouicling stoundasdizntion
Ashe indoace tan deline Lommon hehauo
fox cdiluent tunyelated classea entuntrg that
ike classes, iaedaees can alio be ertnded n Hhese asses inhitnsent the ayaune nethod This
inten date con etenc anothe'atesuface- Thit s spactes centicdeaty ond ollews diffecnt hea af
Similas o how a clocr eyienolt anothey clogtabud ehiecks te be heade polymophi caly
uith aBeores,the Genceht ut ued to tnhet
abetrat nethol iem anotheu intuace, When ) cutdiy Elexthit nlode Lnea atataa
Cnt inteuace etendt anothex,ahexiti aleclefining atAstagle iadeu fote Can allow derbility by
the metioae uom the 2Ient îhdeafae, aud apesaa that Can haue multikte
H can alie dlelave bun oiddrana methdt the piotion inud be Peufcxocd. Thit
al¯cas
cilfeent claces te inplenet the iatofae
Syatax ateding
Chilel Inefaceextudssoda
Pagc 50_ubhash Page 31 ubhash
Date
Date

loce FlyingCan inplemtnts Doiuoble, Elyable


uoid douel)
hultple 'aler or capnhilries at the Jame tint.
a\ Achiesing ttulible daheudasce of
Nutipie inte facel alos akass Behauor
toinhexd
hehauia on mÙne hcun One
essertial n tatians
douvle, shich
uheue a clast neede t mplna
ulithle uh elatat funiona lches
Peablic stahic' woid nsun
FuingCar (0;
Cax.flys

indauqace flycble
ucid Giyc)
Cass C imþlt m
erts H, B

You might also like