— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet80/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   76   77   78   79   80   81   82   83   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

nums
nums[0] = 6;
nums[1] = 19;
nums[2] = 44;
nums[3] = 42;
nums[4] = 10;
nums[5] = 20;
nums[6] = 1;
1
Declare an int array variable. An array variable is 
a remote control to an array object.
int[] nums;
nums = new int[7];
2
Create a new int array with a length 
of 7, and assign it to the previously-
declared 
int[]
variable 
nums
3
Give each element in the array 
an int value. 
Remember, elements in an int 
array are just int variables.
An array is like a tray of cups
int int int int int int int
Notice that the array itself is an object, 
even though the 7 elements are primitives.
7 int variables
7 int variables


60
 
chapter 3
Dog array object (Dog[])
Dog[]
pets
pets[0] = new Dog();
pets[1] = new Dog();
1
Declare a Dog array variable 
Dog[] pets;
pets = new Dog[7];
2
Create a new Dog array with 
a length of 7, and assign it to 
the previously-declared 
Dog[]
variable 
pets
3
Create new Dog objects, and 
assign them to the array 
elements. 
Remember, elements in a Dog 
array
are just Dog reference 
variables
. We still need Dogs!
Make an array of Dogs
Dog Dog Dog Dog Dog Dog Dog
an 
array
 of objects
What’s missing?
Dogs! We have an array 
of Dog references, but no 
actual Dog objects!
Dog array object (Dog[])
Dog[]
pets
Dog Dog Dog Dog Dog Dog Dog
Do
g Object
Do
g Object
Sharpen your pencil
What is the current value of 
pets[2]? ___________
What code would make 
pets[3] refer to one of the 
two existing Dog objects?
_______________________



Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   76   77   78   79   80   81   82   83   ...   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