All the code below is in the file CatFish.java. Complete the classes below. Keep it
very simple. The code you write must produce the output shown at the bottom of the
page. Read the whole problem first - how you follow later instructions may affect early choices. Assume you
have any import atatements you need. You may not need all blank lines.
interface Movers{
public void move(); //this method will print (see output below)
}
class Cat _____________________________{
_____________________________________
_____________________________________
_____________________________________
}
class Fish _____________________________{
_____________________________________
_____________________________________
_____________________________________
}
class Exam{
public static void main(String[] args){
Collection<Movers> movers = ______________________________
//make two objects and put them in the collection (read output below first!)
_____________________________________
_____________________________________
//use a for-each loop to print collection
_____________________________________
_____________________________________
_____________________________________
}
}
Type the shell1 command to compile:
bash-3.2$ ______________________________
Type the shell command to run, and see the actual output below:
bash-3.2$ ______________________________
swims like a fish
runs like a cat
Explanation: I have written all the three classes and have filled all the blanks as mentioned in the question.Please upvote if you liked my answer and comment if you need any modification or explanation.
//Cat
public class Cat implements Movers {
@Override
public void move() {
System.out.println("runs like a
cat");
}
}
//Fish
public class Fish implements Movers {
@Override
public void move() {
System.out.println("swims like a
fish");
}
}
//Exam class
import java.util.ArrayList;
import java.util.Collection;
public class Exam{
public static void main(String[] args) {
Collection<Movers> movers =
new ArrayList<Movers>();
movers.add(new Fish());
movers.add(new Cat());
for (Movers mover : movers) {
mover.move();
}
}
}
Output:
Get Answers For Free
Most questions answered within 1 hours.