— Scott McNealy, Sun Microsystems Chairman, President and ceo


exercise:  Mixed Messages



Download 40,57 Mb.
Pdf ko'rish
bet187/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   183   184   185   186   187   188   189   190   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

exercise: 
Mixed Messages

M
i


x
e
d
M
e
s
s
a
g
e
s


inheritance and 
polymorphism
you are here
4
193
Which of the A-B pairs of methods listed on the right, if 
inserted into the classes on the left, would compile and 
produce the output shown? (The A method inserted into 
class Monster, the B method inserted into class Vampire.)
BE the Compiler
public class MonsterTestDrive {
public static void main(String [] args) {
Monster [] ma = new Monster[3];
ma[0] = new Vampire();
ma[1] = new Dragon();
ma[2] = new Monster();
for(int x = 0; x < 3; x++) {
ma[x].frighten(x);
}
}
}
class Monster {
}
class Vampire extends Monster { 
}
class Dragon extends Monster {
boolean frighten(int degree) {
System.out.println(“breath fire”);
return true;
}
}
File Edit Window Help Sleep
% java TestArrays
island = Fiji
island = Cozumel
island = Bermuda
island = Azores
File Edit Window Help SaveYourself
% java MonsterTestDrive
a bite?
breath fire
arrrgh
boolean frighten(int d) {
System.out.println(“arrrgh”);
return true;
}
boolean frighten(int x) {
System.out.println(“a bite?”);
return false;
}
boolean frighten(int x) {
System.out.println(“arrrgh”);
return true;
}
int frighten(int f) {
System.out.println(“a bite?”);
return 1;
}
boolean frighten(int x) {
System.out.println(“arrrgh”);
return false;
}
boolean scare(int x) {
System.out.println(“a bite?”);
return true;
}
boolean frighten(int z) {
System.out.println(“arrrgh”);
return true;
}
boolean frighten(byte b) {
System.out.println(“a bite?”);
return true;
}

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   183   184   185   186   187   188   189   190   ...   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