— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet92/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   88   89   90   91   92   93   94   95   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

int z = x + y;
System.out.println(“Total is ” + z);
}
void go() {
int foo = 7;
int bar = 3; 
t.takeTwo(foo, bar);
}
You can pass variables into a method, as long as 
the variable t ype matches the parameter t ype.
The values of foo and bar land in the 
x and y parameters. So now the bits in 
x are identical to the bits in foo (the 
bit pattern for the integer ‘7’) and the 
bits in y are identical to the bits in bar.
What’s the value of z? It’s the same 
result you’d get if you added foo + 
bar at the time you passed them into 
the takeTwo method


you are here
4
methods 
use 
instance variables
77
Java is pass-by-value.
That means pass-by-copy.
int x = 7;
00000111
int
X
1
Declare an int variable and assign it 
the value ‘7’. The bit pattern for 7 
goes into the variable named x.
void go(int z){ }
2
Declare a method with an int 
parameter named z. 
int
Z
00000111
int
X
3
Call the go() method, passing 
the variable x as the argument. 
The bits in x are copied, and 
the copy lands in z.
00000111
int
Z
copy of x
foo.go(x);
void go(int z){ }
00000111
int
X
4
Change the value of z inside 
the method. The value of x 
doesn’t change! The argument 
passed to the z parameter was 
only a copy of x. 
The method can’t change the 
bits that were in the calling 
variable x.
int
Z
void go(int z){
z = 0; 
}
x doesn’t change, 
even if z does.
00000000
x and z aren’t 
connected



Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   88   89   90   91   92   93   94   95   ...   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