— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet54/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   50   51   52   53   54   55   56   57   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

34
 
chapter 2
thinking about 
objects
ShoppingCart
cartContents
addToCart()
removeFromCart()
checkOut()
knows
does
Button
label
color
setColor()
setLabel()
dePress()
unDepress()
knows
does
Alarm
alarmTime
alarmMode
setAlarmTime()
setAlarm()
isAlarmSet()
snooze()
knows
does
When you design a class, think about the objects that 
will be created from that class t ype. Think about:

things the object 
knows

things the object 
does
Things an object 
knows about itself are called

instance variables
Things an object can 
do are called

methods
Song
title
artist
setTitle()
setArtist()
play()
instance
variables
(state)
methods
(behavior)
knows
does
Things an object knows about itself are called instance 
variables. They represent an object’s state (the data), and 
can have unique values for each object of that type. 
Think of 
instance
 as another way of saying 
object

Things an object can do are called methods. When you 
design a class, you think about the data an object will need 
to know about itself, and you also design the methods 
that operate on that data. It’s common for an object to 
have methods that read or write the values of the instance 
variables. For example, Alarm objects have an instance 
variable to hold the alarmTime, and two methods for 
getting and setting the alarmTime.
So objects have instance variables and methods, but those 
instance variables and methods are designed as part of the 
class.
Sharpen your pencil
Fill in what a television object 
might need to know and do.
Alarm

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   50   51   52   53   54   55   56   57   ...   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