— Scott McNealy, Sun Microsystems Chairman, President and ceo



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

are alive and in scope, 
and ‘b’ is alive but 
not 
in scope. 
crazy() is pushed onto 
the Stack, with ‘c’ now 
alive and in scope. The 
other three variables 
are alive but out of 
scope.
crazy() completes and 
is popped off the Stack, 
so ‘c’ is out of scope 
and dead. When go() 
resumes where it left 
off, ‘x’ and ‘z’ are both 
alive and back in scope. 
Variable ‘b’ is still alive 
but out of scope (until 
go() completes).
Life
Scope
A local variable is alive as long as its Stack 
frame is on the Stack. In other words, 
until the method completes.
A local variable is in scope only within the 
method in which the variable was declared. 
When its own method calls another, the 
variable is alive, but not in scope until its 
method resumes. You can use a variable only 
when it is in scope
.
The difference between 
life
 
and 
scope
 for local variables:
2
3
4
While a local variable is alive, its state persists. 
As long as method doStuff() is on the Stack, for 
example, the ‘b’ variable keeps its value. But the 
‘b’ variable can be used only while doStuff()’s 
Stack frame is at the top. In other words, you can 
use a local variable only while that local variable’s
method is actually running (as opposed to 
waiting for higher Stack frames to complete).


object 
lifecycle
260
 
chapter 9
The rules are the same for primtives and references. A reference 
variable can be used only when it’s in scope, which means you can’t use 
an object’s remote control unless you’ve got a reference variable that’s 
in scope. The real question is, 

Download 40,57 Mb.

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