— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet191/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   187   188   189   190   191   192   193   194   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

interfaces and 
polymorphism
you are here
4
199
Wolf aWolf = new Wolf();
We know we can say:
A Wolf reference to a 
Wolf object.
Wolf
aWolf
W
ol
f
o
b
je
ct 
These two are the same type. 
Animal aHippo = new Hippo();
And we know we can say:
Animal reference to 
a Hippo object.
Animal
aHippo
Hip
po
o
b
je
ct 
These two are NOT the same type. 
Animal anim = new Animal();
But here’s where it gets weird:
Animal reference to 
an Animal object.
Animal
anim
A
n
i
mal
o
bj
e
ct
These two are the same type, but...
what the heck does an Animal object look like?
?


200
 
chapter 8
scary objects 
What does a new Animal()
object 
look like?
when objects go 
bad 
It makes sense to create a Wolf object or a Hippo 
object or a Tiger object, but what exactly is an 
Animal object? What shape is it? What color, size, 
number of legs...
Trying to create an object of type Animal is like 
nightmare Star Trek™ transporter accident. The 
one where somewhere in the beam-me--up process 
something bad happened to the buffer.
But how do we deal with this? We need an Animal 
class, for inheritance and polymorphism. But we 
want programmers to instantiate only the less 
abstract subclasses of class Animal, not Animal itself. 
We want Tiger objects and Lion objects, not Animal 
objects
.
Fortunately, there’s a simple way to prevent a class 
from ever being instantiated. In other words, to stop 
anyone from saying “

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   187   188   189   190   191   192   193   194   ...   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