Tnhevitance 1s a very useful and
rful concept of oops in java: J4
deg a greate advantoge caued
é ve -USa lity.
¥
el. : : |
|
The jnhevitane is +he process of
Cving Ane properties of one class te
meee) class
e@ ase five types of
Pie inwervr tance
eoukiple
multi-level «1
wyeearchical
pnhe vi taice: Wye
Hy bail u
yeople imheritance '-
Beye of yohentane gne child class
BANIES fron one Porer class a clas
trnevie fe uses extends keywords
2
> 5
| ed
cid clase
an
i j
eescoe
a
Fas y
3) roultilevel enheritances.
Ta Anis ype of tnhervtawce, the doty
Chill class clevives from a clarke eoheh alse,
devinted from
another claws
cc-
A
a) Werar chicat Toheatate ae
a4U90 Cor) rnore Chik
ome = porent clase
5) ty brick
are cori natto
of Inneri tance:
oxo Si*91e w
{-\eVe w
MOeteG tovtve fron
ia, OTS
ny coro"
tancec
itoncefee eS [
get oasalinre) {
thyYSs a=Q,
law
child class extends parent c £
Jotd chowhatal) §.
system out printia (Tnsicle che id clay)
syctem our priatle (“value 6f a is +a )-
7
i
child class Too extends favent clasS
Word olsplayc )
System out PY Otle (‘anes
mn out » "
ec ee (otue of ats +a):
,
4
mc, jaw 4+lvevarchical Bnteritonce
de chitel class tod),
uBlic stakt< oid vron [strat] age) g
cmile clas chilol- obj = new childclanc ).
child _ oh sate Coo) ; 4
Irild - ob Show Pata() »
-
belo claw Too child Too - oloj = ‘neweht Id class
ee ;
a obj se ar O ; i* xs
the access 4
: wo +,
the scope ox & Clay:
COMETUC tar, akc
memh of clact amd anheritance
“Whe public members can he acces ce
oniexyuoherve .
Bae prune yoevmeers Gam PE aceetten
\ only inside he carne class.
—> We protected perms ate 9 00Cry ,
40 extevry crildclacs ccore Pockage «:
other packoge )
=h The defor members Are accessible
re came packoqe but not ocrsice
‘ tie package.
Jano Corewuctor io inheritance
Iss Tre cefoulk conctructoy of A paren’
coed ausormatically by the construc 4
. it's} cRitd class. thot mMearS when
ie create aco object of the cknld class,
oven’ class consttuctey exerted, $0)!"
[ey the Child clos = Comsttuctoy execu!
penis, forent cos a 5 gull yap
“a 1 a + 4
Parent Cl"
ete! |Do. re
class extends parent clon £
7 clase) §
“, systermod-printin( Tnsicle child clay
7 constvuctort”) |
ic class constructor inheritance .
public Stare Void main(sting [J args )¢
child class obf = new Child lass c).
#4
i
fe
eo super Keyword:
per teeyooord used to refers to ea
nt class object he supey Keyuord
Meme exsere XO | core pre aT
Be Me 3 wabesi ence cohen baRy
ond child class
: yeder poren’ crass «dota smernbers
vefey pore™ Class poerthor's
cad parent clasS congtructor .
super yeyuard iS used insrde the
ss onl.
fey _bore™ class_¢
cat class ord Grd cid class be
ep! 1
Sry,
went C ars
gato ment” mernrers |.
faveclass payest oss t
we um ey
Void Shoes Bata ¢)
sycie OW primia(tancide +he pave’
chow pata Method }
sycrer™ DUL Printi e farent Clase Num
‘ num)
Coss, crnld class extends Parent ciars |
HL HUrN2 = 20;
Ato chousdada ‘og
gygesr OL princi (anes de fhe chi!
i 4 Dota Mejhod |
nam =" +
pumé)nt v :
oject af child 15 neat,
atically cols the paren clay
Co StTUC DY before ts ‘pur Bul,
yarneterized constructor of me
Dmeutt be plied opty UNng
he supes Keyrord = inde ane. € 6
etl AY ~
constructs
the pazarreter! Zeck
Keyword
To cat
the parent cig8s ty aa
Bar be the fevst 51° ternent wnside the
aroust pay —
Lass constructor gota
@ parametey Values.
avo fine Keyuoord |
pel with vauenrs’
ren 2 vauiable defined pith Ihe
pe Keqword, Te becornes 0 one”
rie oes. not ato 8 go rrodlif y
value
ie i
ne"
(ae foo" MEN"
te ord 7
able txarople f
in(sringl J aTHd
of bl ad : 7
2defied with frnat keyed, it
tence Wy any other clay,
» parent clos (
™ wt ou =10,,
Aoi show Date (9 §
sysherroud piel "Taside pavoot Cs
Oy 1 @thoc
chow cate
systerM OU Prinrln(
35
ceil class extends 0
“ou:
or clart (
|
Ive CAKE Keycond Beamer £ |
puLsic start void saain(string (J ngs) ¢ |
|
|
|
|
process of
afferent jeepleroen”™ : ;
Hee methods with diff sbehaviouea =
s . ee
- vun-tome pris
Poly enor phis
mt class f
mum =t0;
xoid groorata (> f
priatin (“P-nside P
method!)
a
sysier™ ous
Class shovoratal
seererss O14 priorn( nuns "+0um),
7
»
4
4
Mins child class extends paren! oesG
Motd chow! 2 OF
Gyttera-ouk priorla(’Deside child clas
‘hows date 6) method")
pesysie out prroiin( eee
,
Saaclaes Pure poly sre phsmog
vie slate orden ( srringt Tors) §
a Fe new parent class¢ yOnretriding, Hoe He),
bending Ihappens at runtinne . Mery,
binding nich Rappers KNOW? Gs a4
cum ime yare finding. Pr 'S KOU!
dynamre rnethod disgatchloo pure
polynorphise :
3 tart, finad,; PH vate comstructor, +
can't be over rvdden,
Alostta. ctor,
=_— ‘ :
‘an anstrack class ‘Ys aclass that
ung,
aiostract ke ywword. To ptheri:
prefixed ua oa. Key wo": -yefere ;
“(reate an o
bace ve fore Ne can
or f
: fmside -the zyava. (ong package |
e methods of okyect class ame.
class a) hashcode as, cloned), norfy( y
fo S*TING C) etc:
classes, inter faces
the packages
package is container of
Bee - package .To Java
divided inte two AY pes.
inal
7 The
classes, interfaces ,
gave #
uile- 19 Packages were incl okey
O efivedVasey —
-*
> The package statement rust be 1!
SO Se rey
Wee Package mame rnust be Sinv.
The package nawnd TOMB Use c,,
case ~noiaton.
SaNte he code in afile : DBe-+ini-+
Packoge. Java and comple 1 Uy,
Ahe Coromond . :
javac-d—~ Befrning Package. ja,
athe (coromand Creates a ditectoty 10!
e package NAT wnypacKage grol +
IDefiming Package. class ts sated \~
je Run he poogran USING Ke -fo)!o
Coramand .
se Befatireg Paesa cs ie
abe nav iol a
e name. class ane
age ny package»
0B java: th scare")
piBlic Class importing example f
public Class Vord rrain(strng( Jorgs) £
scanner read > New carn re ( System i0):
exact CY); 1
af
yar is vead:
t . Y E
eyste ouk printta f You have entered
a.
no!
o + ra
_
synxo%™
port Package Nome: ”
le)
face mypackag e is
java UHL
class verges feamere €
gion \! main (String cao9)§
KEANE TB ad ict)
4 new scan
efint
s ;
» . ie > : or
\ er
Teme r-faces:. a
= r oa Shae A
an forerface is gimilar to a class p but a
contains abstract “methods and stat.
-finat variavtes only. The “imerfaces PY Toy
antthe mechanism +5 deAeve Abs trac tis,
> An Intex face (S$ a Gntainer Of abstrocti,
MEOds and saittc fina} Vosuable-
YP emeg Bupa clOet ocefend AN the,
imeface,
we can't
Defining 7.
imerfa ce Toter-face Manne (f
IMP lemme ote another jter-on
{Menmtarte, aan IMter-faca.| Tanple ne ~aq an ‘ face
> Toterface 1 Plernen bet by P
class uses @ keyeexl —inpte
ype ment i 2
’ an interface: A
implemen’ more vai bs bie:
| syntax) ont
Class classNarne irnplements orgsire
-_ = ‘ ke
boy of the Class
|
Troplementing
aq : lil =
class class nlaroe implents inter fe Maines
Name 2; «fi af 7
4K}
anultiple Dniterfoes ;
paterfa pe:
bobly of -the class
y
nlested_TPorerjace wn Java'-
another
ierfac ane
msrde
arverface ad
“5 public by
ted gnterferce declarer wit
m be with any access id
inside another
be aecessed asTorerface outer Ser. y
Void aute* coethod fn By j
interface tne! imnerfare 7
} a
Class only owler taigerent vin
publyc void oulr method (TfL
Sysrem au. porm to (Shs hc outer;
: avethod”);
5
} \y fnoa ample arnenis outer Toe
clas of 4 1 aa. ses faced
purdce Word jne method (SF
paint (his Is inner interface
rnethod") }
Sysier -oul\ .
d torerface inside o classs- -
i I
imrerface thot defined aclas
lathe nested
moust be accessed as class Name Trnner
pater face:
Usvoociables ro avagpntefaces:-
fa a imierface
she wouabe
Statte and final by dejar: alo access
wood \fer 1S allowed poccept{he public for
interface yauables. Every pouable of a0
ce rust be initialized — the
4 @ publi
1S P' ey
porer{2
ante face reself-
foctending a pntexface (0 JaVae
pote xe can enttenA another PaierfKe.
pnierface CAP extend only one jn test te
can't excterd wnullple interf ACCS
te can jarmpiement nether an pnler{ae
nov class:
tramp:
aanerfoce parent inter fre Sf
Void faxent method C) }
child Torerfare extends paver
i gorerface{
. ool ¢ sy
penprements child
forces.
. ehod PS
| interface methey")"jos | paredk “neshes 0"? 7) Tae
public pavers ee
cycresnsoustpain lng Parent Anrerface ™
4
pac class rtend'ng rnierface { a
| moain( seringl Ja
| public stattc xoid
Teniplerrentng class Obj = new inne lemen
class ¢
ob): chitdl methool ¢ d;
fo} * paxen method C)