— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet248/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   244   245   246   247   248   249   250   251   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

object 
lifecycle
254
 
chapter 9
Can the child exist before 
the parents?
If you think of a superclass as the parent to the subclass child, 
you can figure out which has to exist first. The superclass parts 
of an object have to be fully-formed (completely built) before the 
subclass parts can be constructed
. Remember,
the subclass object might depend on things it 
inherits from the superclass, so it’s important 
that those inherited things be finished. No 
way around it. The superclass constructor 
must finish before its subclass constructor.
Look at the Stack series on page 248 again, 
and you can see that while the Hippo 
constructor is the first to be invoked (it’s 
the first thing on the Stack), it’s the last one 
to complete! Each subclass constructor 
immediately invokes its own superclass 
constructor, until the Object constructor 
is on the top of the Stack. Then Object’s 
constructor completes and we bounce 
back down the Stack to Animal’s 
constructor. Only after Animal’s constructor completes 
do we finally come back down to finish the rest of the Hippo 
constructor. For that reason:
The call to super() must be the 
first statement
in each constructor!*
Eewwww... that 
is SO creepy. There’s 
no way I could have been 
born before my parents. 
That’s just 
wrong.
*There’s an exception to this rule; you’ll learn it on page 252.
Possible constructors for class Boop
public Boop() {
super();
}
public Boop(int i) {
super();
size = i;
}
These are OK because 
the programmer ex-
plicitly coded the call 
to super(), as the first 
statement.

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   244   245   246   247   248   249   250   251   ...   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