Head First Java a brain-Friendly Guide Kathy Sierra and Bert Bates



Download 17,18 Mb.
Pdf ko'rish
bet56/90
Sana22.06.2022
Hajmi17,18 Mb.
#693704
1   ...   52   53   54   55   56   57   58   59   ...   90
Bog'liq
(Head Up) Kathy Sierra Bert Bates - Head First Java, 3rd Edition Early Release-O\'Reilly Media, Inc. (2021)

int giveSecret() {
return 42;
}


If you declare a method to return a value, you 
must
return a value of the
declared type! (Or a value that is 
compatible
with the declared type. We’ll
get into that more when we talk about polymorphism in chapter 7 and
chapter 8.)
Whatever you say you’ll give back, you better give back!
The compiler won’t let you return the wrong type of thing.


You can send more than one thing to a
method
Methods can have multiple parameters. Separate them with commas when
you declare them, and separate the arguments with commas when you pass
them. Most importantly, if a method has parameters, you 
must
pass
arguments of the right type and order.
Calling a two-parameter method, and sending it two
arguments.




There are no Dumb Questions
Q: What happens if the argument you want to pass is an object instead
of a primitive?
A:
You’ll learn more about this in later chapters, but you already 
know
the
answer. Java passes 
everything
by value. 
Everything
. But... 
value
means
bits inside the variable
. And remember, you don’t stuff objects into
variables; the variable is a remote control—
a reference to an object
. So if
you pass a reference to an object into a method, you’re passing a 
copy of the
remote control
. Stay tuned, though, we’ll have lots more to say about this.

Download 17,18 Mb.

Do'stlaringiz bilan baham:
1   ...   52   53   54   55   56   57   58   59   ...   90




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