— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet288/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   284   285   286   287   288   289   290   291   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

304
 
chapter 10
Getting an object that extends Calendar
How in the world do you get an “instance” of an abstract class? 
Well you don’t of course, this won’t work:
This WON’T work:
Calendar cal = new Calendar();
Instead, use the static “getInstance()” method:
Calendar cal = Calendar.getInstance();
Wait a minute. 
If you can’t make an 
instance of the Calendar 
class, what exactly are you 
assigning to that Calendar 
reference?
You can’t get an instance of Calendar, 
but you can can get an instance of a 
concrete Calendar subclass.
Obviously you can’t get an instance of Calendar, because 
Calendar is abstract. But you’re still free to call static methods 
on Calendar, since static methods are called on the class
rather than on a particular instance. So you call the static 
getInstance() on Calendar and it gives you back... an instance 
of a concrete subclass. Something that extends Calendar 
(which means it can be polymorphically assigned to Calendar) 
and which—by contract—can respond to the methods of class 
Calendar.
In most of the world, and by default for most versions of Java, 
you’ll be getting back a java.util.GregorianCalendar instance.
The compiler won’t allow this!
This syntax should look familiar at this 
point - we’re invoking a static method.
getting a 
Calendar


numbers 
and
statics
you are here
4
305
Working with Calendar objects
There are several key concepts you’ll need to understand in 
order to work with Calendar objects:
ß
Fields hold state - A Calendar object has many fields that are used to 
represent aspects of its ultimate state, its date and time. For instance, you 
can get and set a Calendar’s year or month.
ß

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   284   285   286   287   288   289   290   291   ...   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