0% found this document useful (0 votes)
2 views14 pages

multipleInheritance_ObjectClass

The document discusses concepts related to object-oriented programming in Java, including inheritance, abstraction, and method overriding. It provides examples of class definitions, method implementations, and the use of public and private access modifiers. Additionally, it highlights the importance of code reusability and flexibility in software development.

Uploaded by

kaaushick10
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)
2 views14 pages

multipleInheritance_ObjectClass

The document discusses concepts related to object-oriented programming in Java, including inheritance, abstraction, and method overriding. It provides examples of class definitions, method implementations, and the use of public and private access modifiers. Additionally, it highlights the importance of code reusability and flexibility in software development.

Uploaded by

kaaushick10
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/ 14

loelas

clays Ioheited MemberA:


Lenal vartable ll be
Puble statfc
Pnheited.
i / ba ohetted
abstract wotfod will
2 publie fnhertted.
9- Da<ault wettad will be

to clas Inhesttod MenberA :


Sntelaupublc statfe wattcd wlwill not be foharitod.

stafc ond non statfe watteods oill


not be nheîted.

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

Deo. showc); CTS


Mullipe fohesftana wtth espect to clas
and Pnte lae iabesek

laws

Clas

class chfld oskerck


ettencs paseotcas Pnpleuant
farentJnte a, parentnkedau 2,...n

Note :
have
Jn multple Snherttana, i
parent as los
clas ard anotter parent as

nust Octends cays ad


fnter7au, bfrst
ater that we frnplewant fntevfaa
One class but
we Can eztends y
we Can fepleant mterjacs.
intexfaa will not bave any Parent
Aluay class.

Frample:
întevBau Demo

object) clas Test extends cbfect mpleent Damo


T
Tost() Cornpfler wtll
suparl), provfde
(all
Conventan: ral Varfable-ame
wheneve we are

Varlade nam
Varfable need provtde
tully ppar Case.

fzamle: Dav'a <snkegu


Vess ion =1
obatrodetFouwer();
dahault
davta inlo0;
Cawura Muste Plagr
PlauMustc() I
tatsPhotal )
rerdVidooc ) Stopmustc))
obatoct

SroaztPhone
Kelos

publie atex<aca Davta l


fot VERSI ON =
votd powerOnC);
dafault vod davialnlo){
Sopln ('Verafon :"+ VERSION):

public nter<au Canera xtends Deviu f


vofd aka Phots0;
Vofd ucord Video);
publie frtejau MustPlayr ontrnds Dauia!
Vord ufc Playe(0;
voíd
sitpMui';

publie clau SmastPhonu fnplena hts Canwra,


Muate Plaur
þblie vofd pouer Cn(){
Sopnc Pbuer On");
public votd music Plautr(){
S-o pn ("Stast Musse "):

publ'c tofd stop Musfc()f


S.opln ( "Sop Musfe ");
td
public vofd take Phots ()f
So plo (" Taktng Phot ');
public vod weord Videoo4
So pln ("Reordhg vidso");

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

a. Flenibi lity will be more

Based Bur regutrenent we

Can provfde fmplementatfn.


a. Seurit will be more

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

pvent (direct paent ) or supermost parent


(fndirect paunt).
most Cmmn methoolo which
has

Mequl red or al the


ttie Obfecks fo faa.
0bfect clas We have
Jo
non-sta tic ethos.

1 publie Statng Shtngt)


publíe boolaan qua lb(Cbfect o)
3 public hashCod ()iprr
4. protectad votd knalize()
Cley C)
5 proteeted obfect cloe
public nal vofd watt()
7 publie enal void wait( Lng
8. publ'c fnal votd wait (Long,at)
9. publie mal votd noty ()
lo. pablic nal vofd noHgAL ()
11. publie nal class getC las ()
yectclas
Stfnq
Jt uill uaturn geuenat string
Used
an obfect sorena.
termat we are
whanever
will
Vaiabe,

be Callad
faterally
Frample:
Packa abe ;
clas Demo
main( )

Deno d, = new Derno l);


here comptle
Siopln (d, D; uill add' Saty) abe. Dernoabei23
abc.erno bci2g
S.o-pln (di. tboSting),

Strtng fomat :

Package Nae.clas laue OHema Dectmal


bully Qualtfed
buyQualijied laue: clas uith
These Can be mulhiple
aroid
noe in difvent Packy
that Conubn ttay fhvenked fullyQualia
tostrtng) fn Obect clas:

publie Stbhg bStg)!


weturn getEhu ).gethanu().
Jnteye. totexshtng Chash Code
0);

’gtelas()- getauuet) will prouide

Note:
Javaa not rovdinq Origtnal oddes
frstead will ptnt sttng lomat,
wheneer ee t aferena
Vaiable

Overiding ot-tng ():


tsttng () a non-stattc nettod

and eveng clas will have

uatship with Obfect cla,


Objet clas So Can

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,

Yp Band Poco : Pte |2000

osloclas
2quab(obfect o) Object clau
non-stah wettod it
tun boolean.hotea
wed to Compare
Cutent Obfect wfth the

paud ouedt., 2qualst)


Sntax tto call Hs method :

Cument oj.aqualo ( pasad.o);


Current Obfect :
are
An Dkfecwluth we

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

Prioive Data Non-prfmthve data

int byt, ort,lng s ring, Book, shudenk,..


boolean Compae
l) ==
Cho Lsmpare
2) equab0’ rekrenu
a'= = a fn osj clavs
tru te
Example:
clas Book

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;

Book b new Book (ioo);


Book b Book (o o)
Stopln (bi. equab (ba);

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

2) class Pant chss chtld etands Paent

Chject daglay) sy duplay) lCTS

Cbject ttan tte


Can
Oeridlig mettod
subelas

You might also like