— Scott McNealy, Sun Microsystems Chairman, President and ceo


works () inheritance and



Download 40,57 Mb.
Pdf ko'rish
bet164/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   160   161   162   163   164   165   166   167   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

works
()


inheritance and 
polymorphism
you are here
4
169
superclass
Doctor
worksAtHospital
treatPatient ()
Adds one new
instance variable
Adds one new method
subclasses
Overrides the inherited
treatPatient() method
Adds one new method
Surgeon
treatPatient ()
makeIncision()
FamilyDoctor
makesHouseCalls
giveAdvice ()
one instance variable
one method
Sharpen your pencil
How many instance variables does 
Surgeon have?
How many instance variables does 
FamilyDoctor have?
How many methods does Doctor have?
How many methods does Surgeon have?
How many methods does FamilyDoctor 
have?
Can a FamilyDoctor do treatPatient()?
Can a FamilyDoctor do makeIncision()?
public class Doctor {
boolean worksAtHospital;
void treatPatient() {
// perform a checkup
}
}
public class FamilyDoctor extends Doctor {
boolean makesHouseCalls;
void giveAdvice() {
// give homespun advice
}
}
public class Surgeon extends Doctor{
void treatPatient() {
// perform surgery
}
void makeIncision() {
// make incision (yikes!)
}
}
I inherited my 
procedures so I didn’t 
bother with medical school.
Relax, this won’t hurt a bit. 
(now where did I put that 
power saw...)
An inheritance example:


170
 
chapter 7
What do these six types have in 
common? This helps you to abstract 
out behaviors. (step 2)
How are these types related? This 
helps you to define the inheritance 

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   160   161   162   163   164   165   166   167   ...   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