in Education by

What is the output of the following Java program? class Test { public static void main (String args[]) { System.out.println(10 + 20 + "Javatpoint"); System.out.println("Javatpoint" + 10 + 20); } }

Please log in or register to answer this question.

1 Answer

0 votes
by

What is the output of the following Java program?

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

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.

Related questions

...