— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet229/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   225   226   227   228   229   230   231   232   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

public class Duck {
int size;
}
Every Duck has a “size” 
instance variable.
Local variables are declared inside a method, including 
method parameters. They’re temporary, and live only as 
long as the method is on the stack (in other words, as long as 
the method has not reached the closing curly brace).
public void foo(int x) {
int i = x + 3;
boolean b = true; 
}
The parameter x and 
the variables i and b 
are all local variables.
the 
stack
 and the 
heap


constructors and 
gc
you are here
4
237
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’;
}
Methods are stacked
When you call a method, the method lands on 
the top of a call stack. That new thing that’s 
actually pushed onto the stack is the stack 
frame, and it holds the state of the method 
including which line of code is executing, and 
the values of all local variables. 
The method at the top of the stack is always 
the currently-running method for that stack 
(for now, assume there’s only one stack,but in 
chapter 14 we’ll add more.) A method stays on 
the stack until the method hits its closing curly 
brace (which means the method’s done). If 
method
 foo() calls method bar(), method bar() is 
stacked on top of method foo().
bar()
foo()
stack frames
bottom of the stack
top of the stack
local variables 
(including 
parameter x)
A call stack with two methods

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   225   226   227   228   229   230   231   232   ...   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