Head First Java a brain-Friendly Guide Kathy Sierra and Bert Bates


To see if two references are the same (which means they refer to the



Download 17,18 Mb.
Pdf ko'rish
bet65/90
Sana22.06.2022
Hajmi17,18 Mb.
#693704
1   ...   61   62   63   64   65   66   67   68   ...   90
Bog'liq
(Head Up) Kathy Sierra Bert Bates - Head First Java, 3rd Edition Early Release-O\'Reilly Media, Inc. (2021)

To see if two references are the same (which means they refer to the
same object on the heap) use the == operator
Remember, the == operator cares only about the pattern of bits in the
variable. The rules are the same whether the variable is a reference or
primitive. So the == operator returns true if two reference variables refer to
the same object! In that case, we don’t know what the bit pattern is (because
it’s dependent on the JVM, and hidden from us) but we 
do
know that
whatever it looks like, 
it will be the same for two references to a single
object
.
Foo a = new Foo(); 
Foo b = new Foo(); 
Foo c = a; 
if (a == b) { // false } 
if (a == c) { // true } 
if (b == c) { // false }




 SHARPEN YOUR PENCIL
What’s legal?
Given the method below, which of the method calls listed on the right
are legal? Put a checkmark next to the ones that are legal. (Some
statements are there to assign values used in the method calls).
int calcArea(int height, int width) { 
return height * width; 

int a = calcArea(7, 12); 
short c = 7; 
calcArea(c,15); 
int d = calcArea(57); 
calcArea(2,3); 
long t = 42; 
int f = calcArea(t,17); 
int g = calcArea(); 
calcArea(); 
byte h = calcArea(4,20); 
int j = calcArea(2,3,5);


BE the compiler
Each of the Java files on this page represents a complete source file.
Your job is to play compiler and determine whether each of these files
will compile. If they won’t compile, how would you fix them, and if they

Download 17,18 Mb.

Do'stlaringiz bilan baham:
1   ...   61   62   63   64   65   66   67   68   ...   90




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