multipleInheritance_ObjectClass
multipleInheritance_ObjectClass
Frample
fotorfau Derno< cdass Tet fmplement:
Demo
fot a =lo ;
vofd deplay();on
bublic statte vofd show)
publre vofd
deplay)
Vofd test()
duyauit matn)
Sopln (a);
S-opln (Test.a);
show); CTE
laws
Clas
Note :
have
Jn multple Snherttana, i
parent as los
clas ard anotter parent as
Frample:
întevBau Demo
Varlade nam
Varfable need provtde
tully ppar Case.
SroaztPhone
Kelos
Claus Driver
maln()f
Devîce d, = new Smart Ph one );
y Output
Caera ei (Couura)di;
e,. davie Jnlol);
C). take Photo(); Takihy Phs
CË weod Videol); Vidu
MusicPlay
daviaInyo (0; gtat Must
m,
mustcPlaye0; Stop Nusc
Advanlages Abstracion:
(: Code Reusabia
daclare Snce reuse
many
claxs
Bubcls
Tmplfantatton ot
not viaib lor
User,O
4 Veny aDsy atn tatn 9 Text
test tt
Code
we do any modif?eatfen,îoo
Se fmplewentation wl
wll not olfect
anott finplementatton,
Fnal keynd
non -acces
modilier.
e Can
- aríabe
-+ method
clas
I. fnal Vartable
7ina! Varíable Can't be
we Can Creata Anal ariabla
Local Scope a well as
fosfde globat
we Can Creat hnal arfabu
Pruide lass -abstract class fh tenjae
fral Method
Cap't be Owrrtden
Fnal methed
ut we can't
will be Poheríted
new fmplewe ntatfon
pruide
3 inal ca
ba înherited.
Kinal clays Can t
sublas
we can't creae
hral clas.
Fxample: szanner, Sring. Strtiyltt
strnguilder,
Gplden Rule:
Oversfdin
pauntclas Behavíouy / mertod, we
upcas ted Variable, chldelas lrit
impleuantahin will aken wfth Respect
non-stahc mettods. tti
Rule Java.
fnpleentaton to abstrat
To prouide
uethods we golden Rule.
Runte
Golden Rude,
Pos
Butlt-fo clases :
Obfect clas:
a butlt-fo chus
preent hside fava.lang packa
ta uoot clas tor all Haa
class Created Pr-dubud
clas.
class uer- defned
clas be fmme drate
obfect Can
be Callad
faterally
Frample:
Packa abe ;
clas Demo
main( )
Strtng fomat :
Note:
Javaa not rovdinq Origtnal oddes
frstead will ptnt sttng lomat,
wheneer ee t aferena
Vaiable
Orertde
We
bsstiy
eed to Overrde tstng metlod
to prfnt ta stato an Obfect.
Example:
class Mobfla f
brand;
shring
double pria; brand! double
mobtle (Stang priea)
brand;
tas. brand -
pule srng
{ brand4": Pu
Retun "Brord"4
ne Mobilel"Poco" l2000);
Mobile m,
osloclas
2quab(obfect o) Object clau
non-stah wettod it
tun boolean.hotea
wed to Compare
Cutent Obfect wfth the
Cal watthod.
Pased Obfect
Cbfe ct which ae
paafhy
Jormal argumunt.
oquala) fn Objeet Clas:
publie kelen squals (Cojet obj) l
etun
bi
FRample:
clas Book Book b, snew Book (100);
Boo k b Kaw Book (i00);
double piui S.o.pln (b,
Ox|
= bo);
OX2
Bock ( olouble Piu) S.o-pln ( bl. squali (ba): ale
Ox2
tiopria priu
Note :
equaliy Oparator wtll tompae tte
Ckfect
las alyo wfl onpata
ta eteunu an Object
Data
doude pia,
Rook (double piu)
ttis. piu :priu;
object o - bY;
publ'e boolean aquab( Dbject o) Dpcaaiig
Book b (Book)o ; (downcasttnq)
dutuon thi. pie -=b.priu;
No:
we ud to Overrde
Lompae tti stats 'obfet
3) bashCode () Obßect clau
method and t
non-attic
etun fot.
will
bascoe ) my p sAUn who Can
ales adeles.
will Vae
based the obfet
Faample
das Student Studnt &, = new shudntc)
fnt pd; 3.0.pln (si. bash Cod e));
Studint cint id){
unique Tnt value beed
the. id -id;
-addres
185364)2
Overrtdhg weed
hasb Codu C):
Orerle bashCoda ()
to geerat. Vale based
states object.
Fzample:
clas Student student , new sludat
Student (?nt id). S.o.pla (A. hashlo duli);
baed on slet
pubie Pot hauhlode)
J
Mettod
Nen-primttve tuno tipa
tte
metod jee
mehcd etatipe shoud
ttu Ortrdihg
etia
sxampl:
) class chzld etends Paent
clas Paunt
child dsplay) leTS
Paant diglay