PLEASE READ CAREFULLY 2. Type this program and save it as MonsterTest_ firstInit
ID: 3819293 • Letter: P
Question
PLEASE READ CAREFULLY
2.
Type this program and save it as MonsterTest_firstInitialLastName.java (remember, the class name must be change accordingly for me to be able to run your program).
Fill the missing code section and produce the following output:
*** output***
a bite?
breath fire
arrrgh
*** end of output
*/
public class MonsterTestDrive public static void main (String CI args) Monster CI ma new Monster 3 1 ma 01 new Vampire ma 11 new Dragon ma [2] new Monster for int x 3 x++) max] frighten (x) i class Monster INSERT YOUR CODE HERE class vampire extends Monster INSERT YOUR CODE HERE class Dragon extends Monster boolean frighten (int degree) System out println breath fire" return true;Explanation / Answer
save as MonsterTest_firstInitialLastName.java
Compile : javac MonsterTest_firstInitialLastName.java
Run : java MonsterTestDrive
Code -
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);
}
System.out.println("*** end of output");
}
}
class Monster {
public boolean frighten(int x) {
System.out.println("arrrgh");
return true;
}
}
class Vampire extends Monster{
public boolean frighten(int x) {
System.out.println("a bite?");
return true;
}
}
class Dragon extends Monster{
public boolean frighten(int degree){
System.out.println("breath fire");
return true;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.