What is the output of the following Java program no. 1?

  1. class Test
  2. {
  3.     public static void main (String args[])
  4.     {
  5.         System.out.println(10 + 20 + “Javatpoint”);
  6.         System.out.println(“Javatpoint” + 10 + 20);
  7.     }
  8. }

The output of the above code will be

30Javatpoint
Javatpoint1020

Explanation

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.