— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet99/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   95   96   97   98   99   100   101   102   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)


particular value can 
be used, a 
method 
call that returns that 
type can be used.
instead of:
int x = 3 + 24;
you can say:
int x = 3 + one.getSize();


you are here
4
methods 
use 
instance variables
83
How do objects in an array 
behave?
Dog array object (Dog[])
Dog[]
pets
pets[0] = new Dog();
pets[1] = new Dog();
Dog[] pets;
pets = new Dog[7];
Create two new Dog objects, 
and assign them to the first 
two array elements.
Dog Dog Dog Dog Dog Dog Dog
Dog array object (Dog[])
Dog[]
pets
Dog Dog Dog Dog Dog Dog Dog
Do
g Object
Do
g Object
Declare and create a Dog array, 
to hold 7 Dog references.
1
Just like any other object. The only difference is 
how you get to them. In other words, how you get 
the remote control. Let’s try calling methods on 
Dog objects in an array. 
2
pets[0].setSize(30);
int x = pets[0].getSize();
pets[1].setSize(8);
Call methods on the two Dog 
objects.
3
30
size
8
size


84
 
chapter 4
You already know that a variable declaration needs at least a name 
and a type:
int size;
String name;
And you know that you can initialize (assign a value) to the 
variable at the same time:
int size = 420;
String name = “Donny”;
But when you don’t initialize an instance variable, what happens 
when you call a getter method? In other words, what is the value of 
an instance variable before you initialize it?
Declaring and initializing 
instance variables

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   95   96   97   98   99   100   101   102   ...   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