Professional Documents
Culture Documents
2 Lecture begins at 9 08 pm
Agenda
1 Access Modifier I Publin Private Default
2 Method 1
overloading polymorphism
d
3 Inheritance
Le Basics
Cton chaining sup
LAcessmodifierz
Puteded
of
a method
g polymorphism
5 3 Rules questions around inheritance
for
polymorphism
ae
modf.my
Public Private
default
Encapsulation
P
Le capsule
medicine together
putting the
to protect the medicine
environment frog
Encapsulation in 00ps
Lasses
L
Binding attributes behaviour
together
protect the attributes from
outsiworld
th
int age main Cl
Stringham I Student s
new Students
s to
age
s.name sand
B
BA intro
w w
void retros
moi
int
wi
Ch
T Igt
II interest calculation
a.am pigpIvate3
AM notspecified
same class
other classes in same
pkg
pas
classes outside the
Pig
Access
Modifies can be applied to methods
even constructors
A class with a
private constra tors
f is possible
hm A at a
Éj
maine
private Ac
3
a
4of Ao new Ac
why
to make actor private
To control the number of objects
that can be created
default l
d 3
P
P dovuoadng3
oeymoapr.sn
Morph ism
Poly
Lam
Many
On
Multiple
Mayton
L take many
same code can
forms
fo
mPiGtimeGea mg
cling
Polymorph.sn
Run time Method
overrig
ding
class A 2
Hello world
Sys i
Hello name
syso
s
than with
Having more one
fn
name but
same
different signature
what is
A signature
how
fulled
I de all he
f
decision to call the
Is the fn
made attietimeor run time
interview
A Very important tricky
9
question
class Client 2
Main C 2
A AC
obj new
obj funC V
Universe
3 obj fun
fun
I
fan C fun string
data types
signature
fame
parameter list of
The the parameter are
names
of
not a
part of signature
void int j
fun string I
A
of signature
s
bid fan string
y
Ing fun strings
Return type is not a
part of
signature
int C byte C short f
h stage
Array sort t
looo
IBreak to. l
Inheritance
Polymorphisms
Lpo pus
Inheritance
Relationships in
hierarchy
A
t
B
B derives
from A
A is the point B is the
B anode behaviours
of
A
BA
saifaTmgf Cmaf
tptehequat.c
I
Trocodile
dat lizards
bre h Tzu
T
Ikfi
B
P
i
p
User
student TA
if
Instructor
Me ta
É
Is A Inheritance allows us to
implement is a relation
is
Labrador a
Dog
is a Mammal
Dog
Mammal is a Animal
Tiga
O
P
D
to
B has d a dl
C has d d f dz
make object CC
If of
we an
u n
n d
B'sconst
A's const
C C
obj new
p
We are
calling only
C's construifor
C's afar will invoke
B's Caton
B's Coton will invoke
A A's stor
p
B i Whose ctor will be called
P first
C 2 Whose ctor will
finish
first
Iott
i
L
one
LWD
AM
Inheritance And
I int
7
parte int dy
10000
s
pj's.am
B is in
pkg
Fa
Same
dsam
Tass figs.me gig gig
pkg
Private
II
t
D
Public
Polymorphism
B G
Ac B new BCS
I new b
f
X b newt
new Bo
new C C
c a new
P
T x
1cinent
A B b
1
Or or
ne
A a new Bl
_b
b
ÉqD A
I
a new
I
Act
B
A a ne Ba
15
c
1
É
b d Bid I
b
find
I
EIIII A a new AC r
A
r
B
I É
1B_1 XX
Compile time error
A a new Ac
Polymorphism
A a new Bc
Itt 2 ne BD
new C
A
P
B
P
on
B
F
or g
A has
on
I ti
2 can add
more c ffn I
on behaviors
3 con override
A
193.1mi
Dj
to
A a new AC
A's fan
a
fund
r
i new
es
a
fund B's fun
x
a new
2
C c's fan
fun
a
Client 2
main C
A getAn Object
a
full
3
A get An Object CI T
s
if Ciselict i
return Anew AC
s
uselect 279
eif 2
BCS
return new
s
g
s
e
return new C
3 g
It is made when
D program is
running
which to call
JVM decides fn
based the instance not
on of of
object
f
f D
A fun a a new BC
T
a
fund
alone
Mif
iI
Tagore
Rl sees the reference one
Cough
I
man
by compiler Isions
JVM makes run time
g reference
says applies to date me bed
d2 200
A's
faut
Ei
fan B's i
fun
g
11 3
s
fan fun 2s
case
a
ICa a to
Font a did a 100
di
x sont
a
P CTE
a
fault A A's fan
y a
funk A A's f
MMA CTE
cee
LHS
Case 2
sont la d Rules lo
a sort F d2 CTE
A
a
fine
II A's fl
a
fac A CTE
P
iI
i
8h
E
Case 4
Bye MAI
sont o dl
j
I g
i
O
fans
Case 3
B o new BC
sont Co di too
soaco.az no
o
fc B's f
A's f
o
fic
o f2C B's f2
AClole
M f A's
f
Atf
t
YYI
fl
A at new BC a d lo
B T new BC b de 2