— Scott McNealy, Sun Microsystems Chairman, President and ceo


new ; there is no other way



Download 40,57 Mb.
Pdf ko'rish
bet245/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   241   242   243   244   245   246   247   248   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

new
; there is no other way to create 
an object other than someone, somewhere saying 
new 
on the class type), the object 
gets space for all the instance variables, from all the way up the inheritance tree. Think 
about it for a moment... a superclass might have setter methods encapsulating a private 
variable. But that variable has to live somewhere. When an object is created, it’s almost as 
though multiple objects materialize—the object being new’d and one object per each 
superclass. Conceptually, though, it’s much better to think of it like the picture below, 
where the object being created has 
layers of itself representing each superclass.
There is only ONE object on the heap here. A 
Snowboard object. But it contains both the 
Snowboard parts of itself and the Object parts of 
itself. All instance variables from both classes have 
to be here.
Snowboard also has instance 
variables of its own, so to make 
a Snowboard object we need 
space for the instance variables 
of both classes.
Object
Snowboard
Snowboa
rd ob
jec
t
A single 
object on 
the heap
Object has instance variables 
encapsulated by access methods. 
Those instance variables are 
created when any subclass is 
instantiated. (These aren’t the 
REAL Object variables, but we 
don’t care what they are since 
they’re encapsulated)
Object
Foo a;
int b;
int c;
equals()
getClass()
hashCode()
toString()
Snowboard
Foo x
Foo y
int z
turn()
shred()
getAir()
loseControl()
b C
a
Z
Y
X
space for an object’s 
superclass 
parts



Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   241   242   243   244   245   246   247   248   ...   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