— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet169/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   165   166   167   168   169   170   171   172   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

Wolf
Canine
roam()
makeNoise()
eat()
Animal
makeNoise()
eat()
sleep()
roam()
When you call a method on an object 
reference, you’re calling the most specifi c 
version of the method for that object type.
In other words, the lowest one wins! 
“Lowest” meaning lowest on the 
inheritance tree. Canine is lower than 
Animal, and Wolf is lower than Canine
so invoking a method on a reference 
to a Wolf object means the JVM starts 
looking fi rst in the Wolf class. If the JVM 
doesn’t fi nd a version of the method in 
the Wolf class, it starts walking back up 
the inheritance hierarchy until it fi nds a 
match.


176
 
chapter 7
Draw an inheritance diagram here.
practice designing an 
inheritance 
tree
there are no
Dumb Questions
Q: 
You said that the JVM starts 
walking up the inheritance tree, 
starting at the class type you invoked 
the method on (like the Wolf example 
on the previous page). But what 
happens if the JVM doesn’t ever find 
a match?
A: 
Good question! But you don’t 
have to worry about that. The compiler 
guarantees that a particular method 
is callable for a specific reference type, 
but it doesn’t say (or care) from which 
class that method actually comes from 
at runtime. With the Wolf example, the 
compiler checks for a sleep() method, 
but doesn’t care that sleep() is actually 
defined in (and inherited from) class 
Animal. Remember that if a class 
inherits a method, it has the method. 
Where the inherited method is defined 
(in other words, in which superclass 
it is defined) makes no difference to 
the compiler. But at runtime, the JVM 

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   165   166   167   168   169   170   171   172   ...   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