Analyze the following code using The java.lang.Comparable interface :

Analyze the following code using The java.lang.Comparable interface :

public class Test1  {  public Object max(Object o1, Object o2) {    if ((Comparable)o1.compareTo(o2) >= 0) {      return o1;    }    else {      return o2;    }  }}


A. The program has a compile error because Test1 does not have a main method.
B. The program has a compile error because o1 is an Object instance and it does not have the compareTo method.
C. The program has a compile error because you cannot cast an Object instance o1 into Comparable.
D. The program would compile if ((Comparable)o1.compareTo(o2) >= 0) is replaced by (((Comparable)o1).compareTo(o2) >= 0).

The correct answer is BD

Explanation: The . operator is performed before casting.


Java

Learn More Multiple Choice Question :