Analyze the following code. public class Test { public static void main(String[] args) { Number x = new Integer(3); System.out.println(x.intValue()); System.out.println((Integer)x.compareTo(new Integer(4))); } }

Analyze the following code.
public class Test {
  public static void main(String[] args) {
    Number x = new Integer(3);
    System.out.println(x.intValue());
    System.out.println((Integer)x.compareTo(new Integer(4)));
  }
}


A. The program has a compile error because an Integer instance cannot be assigned to a Number variable.
B. The program has a compile error because intValue is an abstract method in Number.
C. The program has a compile error because x cannot be cast into Integer.
D. The program has a compile error because the member access operator (.) is executed before the casting operator.
E. The program compiles and runs fine.

The correct answer is D


Java

Learn More Multiple Choice Question :