Site Search:

OCPJP Simulation Test 32

<Back to OCPJP





Question: What is the output of the following program.


  1 import java.util.*;
  2 class ComparableBird<T> implements Comparable<T> {
  3   private int weight;
  4   public ComparableBird(int weight) {this.weight = weight;}
  5   public int getWeight() {return weight;}
  6   @Override
  7   public int compareTo(T t) {
  8     return this.weight > t.getWeight() ? 1 : (this.weight == t.getWeight() ? 0:-1);
  9   }
 10   @Override
 11   public String toString() {return weight + "";}
 12 }
 13 public class Birds{
 14   public static void main(String args[]) {
 15     List<ComparableBird> list = new ArrayList<>();
 16     list.add(new ComparableBird(13));list.add(new ComparableBird(9));list.add(new ComparableBird(12));
 17     Collections.sort(list);
 18     System.out.println(list);
 19   }}

Choice:
A. [13, 9, 12]
B. [9, 12, 13]
C. [13, 12, 9]
D. output is none of the above options
E. compiler error at line 2
F. compiler error at line 7
G. compiler error at line 8
H. compiler error at other lines