— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet193/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   189   190   191   192   193   194   195   196   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

}
}
File Edit Window Help BeamMeUp
% javac MakeCanine.java
MakeCanine.java:5: Canine is abstract; 
cannot be instantiated
c = new Canine();
^
1 error
class Canine is marked abstract,
so the compiler will NOT let you do this.
An 
abstract class
has virtually* no use, no value, no 
purpose in life, unless it is 
extended.
With an abstract class, the guys doing the work at runtime 
are 
instances of a 
subclass 
of your abstract class.
This is OK, because you can always assign 
a subclass object to a superclass reference, 
even if the superclass is abstract.
*There is an exception to this—an abstract class can 
have static members (see chapter 10).


202
 
chapter 8
Abstract vs. Concrete
A class that’s not abstract is called 
concrete class. In the Animal 
inheritance tree, if we make 
Animal, Canine, and Feline 
abstract, that leaves Hippo, Wolf, 
Dog, Tiger, Lion, and Cat as the 
concrete subclasses. 
Flip through the Java API and 
you’ll fi nd a lot of abstract classes, 
especially in the GUI library. What 
does a GUI Component look 
like? The Component class is the 
superclass of GUI-related classes 
for things like buttons, text areas, 
scrollbars, dialog boxes, you name 
it. You don’t make an instance of 
a generic Component and put it on 
the screen, you make a JButton. In 
other words, you instantiate only a 
concrete subclass of Component, but 
never Component itself.
Tiger
Animal
Canine
abstract
abstract
abstract
Hippo
concrete

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   189   190   191   192   193   194   195   196   ...   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