— Scott McNealy, Sun Microsystems Chairman, President and ceo


new ” on that type. By marking  the class as  abstract



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

new
” on that type. By marking 
the class as 
abstract
, the compiler will stop any 
code, anywhere, from ever creating an instance of 
that type. 
You can still use that abstract type as a reference type. 
In fact,that’s a big part of why you have that abstract 
class in the fi rst place (to use it as a polymorphic 
argument or return type, or to make a polymorphic 
array). 
When you’re designing your class inheritance 
structure, you have to decide which classes are 
abstract and which are concrete. Concrete classes are 
those that are specifi c enough to be instantiated. A 
concrete class just means that it’s OK to make objects 
of that type. 
Making a class abstract is easy—put the keyword 
abstract
before the class declaration:
abstract class Canine extends Animal {
public void roam() { }
}
What are the instance variable values?
Some classes just should
not
be 
instantiated! 


interfaces and 
polymorphism
you are here
4
201
The compiler won’t let you instantiate 
an abstract class
An abstract class means that nobody can ever make a new 
instance of that class. You can still use that abstract class as a 
declared reference type, for the purpose of polymorphism, but 
you don’t have to worry about somebody making objects of that 
type. The compiler guarantees it.
abstract public class Canine extends Animal 
{
public void roam() { }
}
public class MakeCanine {
public void go() {
Canine c; 
c = new Dog();
c = new Canine(); 
c.roam();

Download 40,57 Mb.

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