Site Search:

OCPJP Simulation Test 37

<Back to OCPJP





Question: What's the output of the following program?


  1 import java.util.*;
  2 class Tiger extends Cat {public String toString(){return "tiger";}}
  3 class Cat {public String toString(){return "cat";}}
  4 public class Cats {
  5   public static void main(String[] args) {
  6     List<Cat> cats = new ArrayList<>();
  7     cats.add(new Cat());
  8     cats.add(new Tiger());
  9     catDisplay(cats);
 10   }
 11   private static void catDisplay(List<Cat> cats) {
 12     for(Cat cat: cats) {
 13       System.out.println(cat);
 14     }}}


Choice:
A. cat
B. tiger
C. ClassCastException at run time
D. compiler error at line 7
E. compiler error at line 8
F. compiler error at line 9
G. compiler error at other lines