— Scott McNealy, Sun Microsystems Chairman, President and ceo



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

class PoorDog {
private int size; 
private String name;
 
public int getSize() {
return size;

public String getName() {
return name;
}
}
public class PoorDogTestDrive {
public static void main (String[] args) {
PoorDog one = new PoorDog();
System.out.println(“Dog size is “ + one.getSize());
System.out.println(“Dog name is “ + one.getName());
}
}
Instance variables 
always get a 
default value. If 
you don’t explicitly 
assign a value 
to an instance 
variable, or you 
don’t call a setter 
method, the 
instance variable 
still has a value!
integers 
 
0
floating points 
0.0
booleans 
 
false
references 
 
null
declare two instance variables, 
but don’t assign a value
What will these return??
What do you think? Will 
this even compile?
File Edit Window Help CallVet
% java PoorDogTestDrive
Dog size is 0
Dog name is null
You don’t have to initialize instance variables, 
because they always have a default value. Number 
primitives (including char) get 0, booleans get false, 
and object reference variables get null.
(Remember, null just means a remote control that 
isn’t controlling / programmed to anything. A 
reference, but no actual object.
initializing 
instance 
variables


you are here
4
methods 
use 
instance variables

Download 40,57 Mb.

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