— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet106/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   102   103   104   105   106   107   108   109   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

What did Jai suspect?
Will he get out of Leveler’s skimmer with all his bones intact?
Five-Minute
Mystery
puzzle: 
Five Minute Mystery


you are here
4
methods 
use 
instance variables
93
A class can have any number of these.
A method can have only one of these.
This can be implicitly promoted.
I prefer my instance variables private.
It really means ‘make a copy’.
Only setters should update these.
A method can have many of these.
I return something by definition.
I shouldn’t be used with instance variables
I can have many arguments.
By definition, I take one argument.
These help create encapsulation.
I always fly solo.
instance variables, getter, setter,method
return
return, argument
encapsulation
pass by value
instance variables
argument
getter
public
method
setter
getter, setter, public, private
return
A
Class ‘XCopy’ compiles and runs as it stands ! The 
output is: ‘42 84’. Remember Java is pass by value, (which 
means pass by copy), the variable ‘orig’ is not changed by the 
go( ) method.
B
class Clock {
String time;
void setTime(String t) {
time = t;
}
String
getTime() {
return time;
}
}
class ClockTestDrive {
public static void main(String [] args) {
Clock c = new Clock();
c.setTime(“1245”);
String tod = c.getTime();
System.out.println(“time: “ + tod);
}
}
Note: ‘Getter’ methods have a return
type by definition. 
Exercise Solutions



Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   102   103   104   105   106   107   108   109   ...   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