— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet178/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   174   175   176   177   178   179   180   181   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)


particularly motivating.


184
 
chapter 7
the way 
polymorphism 
works
Dog myDog 
= new Dog();
Tells the JVM to allocate space for a 
reference variable. The reference variable 
is, forever, of type Dog. In other words, 
a remote control that has buttons to 
control a Dog, but not a Cat or a Button 
or a Socket. 
1
Declare a reference 
variable
Dog
myDog
Dog myDog =
 new Dog();
Tells the JVM to allocate space for 
a new Dog object on the garbage 
collectible heap.
2
Create an object
Dog myDog = new Dog();
The 3 steps of object 
declaration and assignment
1
2
3
Dog object
Dog myDog
 
=
 
new Dog();
Assigns the new Dog to the refer-
ence variable myDog. In other words, 
program the remote control.
3
Link the object 
and the reference
Dog object
Dog
myDog
To see how polymorphism 
works, we have to step back 
and look at the way we 
normally declare a reference 
and create an object...


inheritance and 
polymorphism
you are here
4
185
The important point is that the 
reference type AND the object 
type are the same. 
In this example, both are Dog.
Dog
myDog
Dog object 
These two are the same type. The reference 
variable type is declared as Dog, and the object 
is created as new Dog().
But with polymorphism, the 
reference and the object can 
be 
different.

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   174   175   176   177   178   179   180   181   ...   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