— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet252/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   248   249   250   251   252   253   254   255   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

}
public class Life {
int size;
public void setSize(int s) {
size = s;
// ‘s’ disappears at the 
// end of this method,
// but ‘size’ can be used
// anywhere in the class
}
}
Variable ‘s’ (this time a method parameter) 
is in scope only within the setSize() 
method. But instance variable size is 
scoped to the life of the object as opposed 
to the life of the method.
BAD!! Not legal to 
use ‘s’ here!
The variable ‘s’ is alive, but in scope only within the 
read() method. When sleep() completes and read() is 
on top of the Stack and running again, read() can 
still see ‘s’. When read() completes and is popped off 
the Stack, ‘s’ is dead. Pushing up digital daisies.
sleep() can’t see the ‘s’ variable. Since 
it’s not in sleep()’s own Stack frame, 
sleep() doesn’t know anything about it.
object 
lifespan


constructors and 
gc
you are here
4
259
public void doStuff() {
boolean b = true;
go(4);
}
public void go(int x) {
int z = x + 24;
crazy();
// imagine more code here
}
public void crazy() {
char c = ‘a’;
}
doStuff()
b
go()
doStuff()
b
x z
crazy()
c
doStuff()
b
go()
x z
go()
doStuff()
b
x z
1
doStuff() goes on the 
Stack. Variable ‘b’ is 
alive and in scope.
go() plops on top of 
the Stack. ‘x’ and ‘z’ 

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   248   249   250   251   252   253   254   255   ...   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