Java OCA OCP Practice Question 154

Question

What is the result of running this code?

public class MyClass { 
        integer a = Integer.valueOf("1"); 
        public static void main(String[] nums) { 
           integer a = Integer.valueOf("2"); 
           integer b = Integer.valueOf("3"); 
           System.out.println(a + b); 
       } 
} 
  • A. 4
  • B. 5
  • C. The code does not compile.
  • D. The code compiles but throws an exception at runtime.


C.

Note

There is no class named integer.

There is a primitive int and a class Integer.

The code does not compile, and Option C is correct.

If the type was changed to Integer, Option B would be correct.




PreviousNext

Related