Java Notes
Java Notes
PART
packqe
java doesn support prepoeesDY ditectives (tfnelde)
’java
Generally to e classes from ofbr poqrams withtat Copn9 physicay
thà can be done i qova by msng packaaqea
’ packages prvides way to achteve yewsabiliky
a
"pabit
Cxeate a subdirechy to sfore clas leu, Subdirechry name mut be
(ame as pockaqe Dame
Compile te le [o that elas de iu Ltoreol subdiseetoy
Same package No
subclas
Yes Yes Yey
Same pakage
Don- Sublas Yes Yes
Dfereot pockage NO
subclas les
ifereot packaqe No No No Yes
non-uhas
Aava inehdes the npot Slacment to bing Crea! ckeat certaio, clauer oY
entire package into visEify
Dmport attmenl is a conveoieot to the
proqramex ies pro qrammer
te ehnieay nof voriing Complek
proaram.
Do java Souvce jde ,import Sakement are
joeloTed by packaqe
Statement
Gener a tm of tfe imprt
ünprrt pockaye - Dame, clau Dame (or)
packaqe decond;
pubat class cg
mput econd
elas packago
pubie slatic void main
CSting argst)
Ca (2 0t
UNIT
imptchy pastie.
syntan t access inace nter7ace-name
vecd displ ay
veid dispiay)
methyd in clan 'A"):
Display
Syoem. ut ntin ("
tnterface Potr
ntoface
Syukem
System ot. pintin j)s
Demo
elavs Dnkntace
bub subv
Potgace 2 method
(e20.
Neskd
otbin another nterace 0r clas is
intenface ie, declared
koon as nested tntotaee
are mico to elate d inteofaces so that
y Phe neted Bextaces
Can be casy to masBain.
ntnface trust he veferrecl by thx buttr lnkr7ace
- qhe natkd class
48
Void soply}
Lokrfae Mexs aqe
vod Msqcs
las Nestedtnkvface 1 implernenk Showable.Meaqe
3
clas Tet Neste d okface
Ohtput s nplementh
bpey Poknfae
adejkied it Can be fimpienentd by anY
y nee an
numb Df claes
avea of crcle - pi r* YS
-"+ area of circle);
of circle
sysfem- bn pintn ( Area
area of rec)s
ao C"Area of Recangle = t
elas Acas
f
publie sfatic void ( stinq argse1)
So
Square Kquares
Rectangle ()3
Reclanole
areal);
l2-*6
Ontput $ Area of circle
Area of &quare
-2vs
Area of Rectangle
Nari abes i loerfaces and enterndhg mterfaeu t
are avadable to any clau
The Conitant values dleciared n inkafa
that implenenk the inkaface
voviakdes
ntegace
nt m2 (0, Dz|S)
Puic void shovoC);
lous arpemo
nùn
pulie sfatie void man (Sfing arqcc1)
b Show);
puhtie sfatic
publir ved main (Sting argsc)
d. show(0;
d. diplaye):
Ontpud i-t0
kz20D