— Scott McNealy, Sun Microsystems Chairman, President and ceo


size: 20 duckCount: 4 Duck



Download 40,57 Mb.
Pdf ko'rish
bet268/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   264   265   266   267   268   269   270   271   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

size: 20
duckCount: 4
Duck
size
static duckCount
getSize()
setSize()
there are no
Dumb Questions


280
 
chapter 10
Earlier in this chapter, we saw that a private 
constructor means that the class can’t be instantiated 
from code running outside the class. In other words, 
only code from within the class can make a new 
instance of a class with a private constructor. (There’s 
a kind of chicken-and-egg problem here. ) 
What if you want to write a class in such a way that 
only ONE instance of it can be created, and anyone 
who wants to use an instance of the class will always 
use that one, single instance? 
Static variables are shared. 
All instances of the same 
class share a single copy of 
the static variables.
instance variables: 1 per 
instance
static variables: 1 per 
class
brainbarbell
Brain Barbell
kid instance one
kid instance two
static variable: 
iceCream
static 
variables


numbers 
and
statics
you are here
4
281
Initializing a static variable
Static variables are initialized when a class is loaded. A class is 
loaded because the JVM decides it’s time to load it. Typically, 
the JVM loads a class because somebody’s trying to make a 
new instance of the class, for the first time, or use a static 
method or variable of the class. As a programmer, you also 
have the option of telling the JVM to load a class, but you’re 
not likely to need to do that. In nearly all cases, you’re better 
off letting the JVM decide when to load the class.
And there are two guarantees about static initialization:
Static variables in a class are initialized before any object of that 
class can be created.
Static variables in a class are initialized before any static method 
of the class runs.

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   264   265   266   267   268   269   270   271   ...   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