— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet209/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   205   206   207   208   209   210   211   212   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

 = new Snowboard();
Object 
o
 = s;
to
St
rin
g() hashC
od
e(
)
ge
tA
ir()
turn()
sh
re
d()
eq
ua
ls()
getC
las
s(
)
loseC
on
tro
l(
)
Object
Snowboard
The Object reference can see only the 
Object parts of the Snowboard object. 
It can access only the methods of class 
Object. It has fewer buttons than the 
Snowboard remote control.
o
s
The Snowboard remote control 
(reference) has more buttons than 
an Object remote control. The 
Snowboard remote can see the full 
Snowboardness of the Snowboard 
object. It can access all the methods 
in Snowboard, including both the 
inherited Object methods and the 
methods from class Snowboard.
S
no
w
b
o
a
r
d
o
b
je
c
t
If a reference is like a remote control, the 
remote control takes on more and more buttons 
as you move down the inheritance tree. A 
remote control (reference) of type Object has 
only a few buttons—the buttons for the exposed 
methods of class Object. But a remote control 
of type Snowboard includes all the buttons from 
class Object, plus any new buttons (for new 
methods) of class Snowboard. The more specific 
the class, the more buttons it may have. 
Of course that’s not always true; a subclass might 
not add any new methods, but simply override 
the methods of its superclass. The key point is 
that even if the object is of type Snowboard, an 
Object reference to the Snowboard object can’t see 
the Snowboard-specific methods.
‘Polymorphism’ means 
‘many forms’. 
You can treat a Snowboard as a 
Snowboard or as an Object.
When you put 
an object in an 
ArrayList, you 
can treat it only as an 
Object, regardless of 
the type it was when 
you put it in.
When you get a 
reference from an 
ArrayList, the 
reference is always of 
type 
Object. 
That means you get an 
Object remote control.
fewer methods here...



Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   205   206   207   208   209   210   211   212   ...   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