Java OCA OCP Practice Question 2085

Question

Consider the following program and determine the output:.

public class Main {
     public void print(Integer i) {
             System.out.println("Integer");
     }/*w ww.j a  v  a 2 s. c  o m*/
     public void print(int i) {
             System.out.println("int");
     }
     public void print(long i) {
             System.out.println("long");
     }
     public static void main(String args[]) {
             Main test = new Main();
             test.print(10);
     }
}
  • A. the program results in a compiler error ("ambiguous overload")
  • B. long
  • C. Integer
  • D. int


D.

Note

if Integer and long types are specified, a literal will match to int.

so, the program prints int.




PreviousNext

Related