Multiple choice

What will be the output of the following code? class Data { public static void main(String arg[]) { int i=12345; String str=”hello”; str=String.valueOf(i); System.out.println(str); } }

  1. Run time error

  2. Compile time error

  3. 12345

  4. hello

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

The String.valueOf() method converts the integer 12345 to its string representation "12345". The original string "hello" is overwritten when str is reassigned. The output is simply the string "12345" printed to console.