Head First Java a brain-Friendly Guide Kathy Sierra and Bert Bates


The case of the pilfered references



Download 17,18 Mb.
Pdf ko'rish
bet53/90
Sana22.06.2022
Hajmi17,18 Mb.
#693704
1   ...   49   50   51   52   53   54   55   56   ...   90
Bog'liq
(Head Up) Kathy Sierra Bert Bates - Head First Java, 3rd Edition Early Release-O\'Reilly Media, Inc. (2021)

The case of the pilfered references
Tawny could see that Kent’s method had a serious flaw. It’s true that he didn’t use as many reference variables as
Bob, but there was no way to access any but the last of the Contact objects that his method created. With each trip
through the loop, he was assigning a new object to the one reference variable, so the previously referenced object
was abandoned on the heap – 
unreachable
. Without access to nine of the ten objects created, Kent’s method was
useless.
(The software was a huge success and the client gave Tawny and Bob an extra week in Hawaii. We’d like to tell
you that by finishing this book you too will get stuff like that.)


Chapter 4. methods use
instance variables: How
Objects Behave
State affects behavior, behavior affects state.
We know that objects have
state
and 
behavior
, represented by 
instance variables
and 
methods
. But
until now, we haven’t looked at how state and behavior are 
related
. We
already know that each instance of a class (each object of a particular type)
can have its own unique values for its instance variables. Dog A can have a


name
“Fido” and a 
weight
of 70 pounds. Dog B is “Killer” and weighs 9
pounds. And if the Dog class has a method makeNoise(), well, don’t you
think a 70-pound dog barks a bit deeper than the little 9-pounder?
(Assuming that annoying yippy sound can be considered a 
bark
.)
Fortunately, that’s the whole point of an object—it has 
behavior
that acts on
its 
state
. In other words, 

Download 17,18 Mb.

Do'stlaringiz bilan baham:
1   ...   49   50   51   52   53   54   55   56   ...   90




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