Question
Not sure what I'm doing wrong. Need help. Please answer the question by writing what is the output from the tester code shown in the
Not sure what I'm doing wrong. Need help.
Please answer the question by writing what is the output from the tester code shown in the bottom box
public class Animal (){ public String species; public Animal(){ species =unknown } public void a1 (){ System.out.println ("Animal 1"); } public void a2(){ System.out.println ("Animal 2"); } public String toString(){ return "Animal String "; } }
| public class Mammal extends Animal{ public int numFeet;
public Mammal (){ super(); numFeet=2; } public void a1 (){ System.out.println(Mammal a1); } public String toString(){ return " Mammal String "; } } |
public class Human extends Mammal { public boolean brain;
public Human (){ super(); brain=true; }
public void a2(){ System.out.println("Human a2"); }
| public class Tester{
public static void main (String []args){ Animal [ ] zoo= { new Mammal(), new Animal ( ), new Human() }; for ( int i=0; i< zoo.length; i++){ zoo[ i ].a1(); System.out.println(zoo[ i ]); zoo[ i ].a2(); } }
|
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started