— Scott McNealy, Sun Microsystems Chairman, President and ceo


public class Dog extends Animal implements



Download 40,57 Mb.
Pdf ko'rish
bet220/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   216   217   218   219   220   221   222   223   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

public class Dog extends Animal implements 
Pet, Saveable, Paintable { ... }
interface 
polymorphism


interfaces and 
polymorphism
you are here
4
227
Make it Stic
k
Roses ar
e red, vio
lets are b
lue.
Extend 
only one
, but imp
lement 
two.
Java we
ighs in o
n family
values: 
Single P
arents O
nly!! A J
ava clas
s can ha
ve 
only on
parent
(superc
lass), an
d that p
arent 
class de
fines wh
o you ar
e. But y
ou can i
mple-
ment m
ultiple i
nterface
s, and th
ose inte
rfaces 
define r
oles you
 can pla
y
How do you know whether to make a 
class, a subclass, an 
abstract class, or 
an interface?
$
Make a class that doesn’t extend anything 
(other than Object) when your new class doesn’t 
pass the IS-A test for any other type.
$
Make a subclass (in other words, 
extend a class) 
only when you need to make a 
more specifi c 
version of a class and need to override or add 
new behaviors.
$
Use an abstract class when you want to defi ne 

template 
for a group of subclasses, and you 
have at least 
some implementation code that all 
subclasses could use. Make the class abstract 
when you want to guarantee that nobody can 
make objects of that type.
$
Use an interface when you want to defi ne a 
role 
that other classes can play, regardless of where 
those classes are in the inheritance tree. 



Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   216   217   218   219   220   221   222   223   ...   555




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish