— Scott McNealy, Sun Microsystems Chairman, President and ceo



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

void go() {
}
But we can declare a method to give a specific type of value 
back to the caller, such as:
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.
Cute... 
but not exactly what I
was expecting.
The bits representing 42 are returned from 
the giveSecret() method, and land in the 
variable named theSecret.
this must fit
in an int!
These types 
must match


76
 
chapter 4
multiple 
arguments
The arguments you pass land in the same 
order you passed them. First argument lands 
in the first parameter, second argument in 
the second parameter, and so on.
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.
void takeTwo(int x, int y) {
int z = x + y;
System.out.println(“Total is ” + z);
}
void go() {
TestStuff t = new TestStuff();
t.takeTwo(12, 34);
}
Calling a t wo-parameter method, and sending 
it t wo arguments.
void takeTwo(int x, int y) {

Download 40,57 Mb.

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