Java OCA OCP Practice Question 2698

Question

Consider the following program and predict the output:

class Main {//from www  .  jav  a2s . co m
         public void print(Integer i){
                 System.out.println("Integer");
         }
         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