What is the output of the following Java program no. 1?
- class Test
- public static void main (String args)
- System.out.println(10 + 20 + “Javatpoint”);
- System.out.println(“Javatpoint” + 10 + 20);
The output of the above code will be
In the first case, 10 and 20 are treated as numbers and added to be 30. Now, their sum 30 is treated as the string and concatenated with the string Javatpoint. Therefore, the output will be 30Javatpoint.
In the second case, the string Javatpoint is concatenated with 10 to be the string Javatpoint10 which will then be concatenated with 20 to be Javatpoint1020.