— Scott McNealy, Sun Microsystems Chairman, President and ceo


all the methods abstract!



Download 40,57 Mb.
Pdf ko'rish
bet217/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   213   214   215   216   217   218   219   220   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

all the methods abstract! 
That way, the subclass must implement the methods 
(remember, abstract methods must be implemented by the fi rst concrete 
subclass), so at runtime the JVM isn’t confused about which of the two 
inherited versions it’s supposed to call.
To DEFINE an interface:
To IMPLEMENT an interface:
public interface Pet {...}
public class Dog extends Canine implements Pet {...}
Use the keyword “interface” 
instead of “class”
Use the keyword “implements” followed 
by the interface name. Note that 
when you implement an interface you 
still get to extend a class 
interfaces 


interfaces and 
polymorphism
you are here
4
225
Making and Implementing 
the Pet interface 
public interface Pet {
public abstract void beFriendly();
public abstract void play();
}
public class Dog extends Canine implements Pet {
public void beFriendly() {...}
public void play() {..}
public void roam() {...}
public void eat() {...}
}
All interface methods are 
abstract, so they MUST end in 
semicolons. Remember, they have 
no body!
You say ‘interface’ instead 
of ‘class’ here
You say ‘implements’ 
followed by the name 
of the interface.
You SAID you are a Pet, so you MUST 
implement the Pet methods. It’s your 
contract. Notice the curly braces 
instead of semicolons.
Dog IS-A Animal 
and Dog IS-A Pet
These are just normal 
overriding methods.
there are no
Dumb Questions
Q:
Wait a minute, interfaces don’t 
really give you multiple inheritance, 

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   213   214   215   216   217   218   219   220   ...   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