If both classes are in the correct directories for their packages, and the Mammal class correctly defines the findSalmon() method, which change allows this code to compile?

Given two files: GrizzlyBear.java and Salmon.java

1. package animals.mammals;
2.
3. public class GrizzlyBear extends Bear {
4. void hunt() {
5. Salmon s = findSalmon();
6. s.consume();
7. }
8. }

1. package animals.fish;
2.
3. public class Salmon extends Fish {
4. public void consume() { /* do stuff */ }
5. }

If both classes are in the correct directories for their packages, and the Mammal class correctly defines the findSalmon() method, which change allows this code to compile?

Given two files: GrizzlyBear.java and Salmon.java

1. package animals.mammals;
2.
3. public class GrizzlyBear extends Bear {
4. void hunt() {
5. Salmon s = findSalmon();
6. s.consume();
7. }
8. }

1. package animals.fish;
2.
3. public class Salmon extends Fish {
4. public void consume() { /* do stuff */ }
5. }

If both classes are in the correct directories for their packages, and the Mammal class correctly defines the findSalmon() method, which change allows this code to compile?

A.
add import animals.mammals.*; at line 2 in Salmon.java

B.
add import animals.fish.*; at line 2 in GrizzlyBear.java

C.
add import animals.fish.Salmon.*; at line 2 in GrizzlyBear.java

D.
add import animals.mammals.GrizzlyBear.*; at line 2 in Salmon.java



Leave a Reply 0

Your email address will not be published. Required fields are marked *