Java OCA OCP Practice Question 1236

Question

What is the output of the following application?

package mypkg; // www.j a  v  a  2s .  com
public class Main { 
        public static Long getScore(Long v) { 
           return 2*v; // m1 
        } 
        public static void main(String[] refs) { 
           final int startTime = 4; 
           System.out.print(getScore(startTime)); // m2 
        } 
} 
  • A. 8
  • B. The code does not compile because of line m1.
  • C. The code does not compile because of line m2.
  • D. The code compiles but throws an exception at runtime.


C.

Note

The variable startTime can be automatically converted to Integer by the compiler,

but Integer is not a subclass of Long.

Therefore, the code does not compile due the wrong variable type being passed to the getScore() method on line m2, and Option C is correct.




PreviousNext

Related