— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet201/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   197   198   199   200   201   202   203   204   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

% java TestObject
class Cat
Cat c = new Cat();
System.out.println(c.hashCode());
hashCode()
3
File Edit Window Help Drop
% java TestObject
8202111
Cat c = new Cat();
System.out.println(c.toString());
toString()
4
File Edit Window Help LapseIntoComa
% java TestObject
Cat@7d277f
Prints out a hashcode 
for the object (for 
now, think of it as a 
unique ID).
Tells you if two objects are 
considered ‘equal’ (we’ll talk 
about what ‘equal’ really 
means in appendix B).
Gives you back the 
class that object was 
instantiated from.
Prints out a String message 
with the name of the class 
and some other number we 
rarely care about.
YourClassHere
Every class you write inherits all the 
methods of class Object. The classes 
you’ve written inherited methods you 
didn’t even know you had.


210
 
chapter 8
there are no
Dumb Questions
Q: 
Is class Object abstract? 
A:
No. Well, not in the formal 
Java sense anyway. Object is a 
non-abstract class because it’s 
got method implementation 
code that all classes can inherit 
and use out-of-the-box, without 
having to override the methods.
Q: 
Then can you override 
the methods in Object? 
A:
Some of them. But some of 
them are marked 
final
, which 
means you can’t override them.
You’re encouraged (strongly) to 
override hashCode(), equals(), 
and toString() in your own 
classes, and you’ll learn how to 
do that a little later in the book. 
But some of the methods, like 
getClass(), do things that must 
work in a specific, guaranteed 
way. 
Q: 

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   197   198   199   200   201   202   203   204   ...   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