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); } }

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

0 votes
    What is the output of the following Java program? class Test { int i; } public class Main { public static void main (String ... test = new Test(); System.out.println(test.i); } }...
asked Nov 19, 2020 in Education by Editorial Staff
0 votes
    What is the output of the following Java program? public class Test { Test(int a, int b) { System.out.println("a = "+a+" b = "+ ... 10; byte b = 15; Test test = new Test(a,b); } }...
asked Nov 19, 2020 in Education by Editorial Staff
0 votes
    What is the output of the following Java program? What is the output of the following Java program? class Test { public static ... ) { System.out.println("Hello Javatpoint"); } } }...
asked Nov 17, 2020 in Education by Editorial Staff
0 votes
    What is the output of the following Java program? class Test { public static void main (String args[]) { System.out.println(10 ... * 20); } } The output of the above code will be...
asked Nov 17, 2020 in Education by Editorial Staff
0 votes
    What will be the output of the following Java program? public class Test { public static void main( ... stackoverflow.com 🔗Source: Java Interview Questions and Answers...
asked Dec 19, 2020 in Technology by Editorial Staff
0 votes
    What is the output of the following Java program? class Test { int test_a, test_b; Test(int a, int b) { test_a = a; ... (); System.out.println(test.test_a+" "+test.test_b); } }...
asked Nov 19, 2020 in Education by Editorial Staff
0 votes
    What will be the output of the following Python program? z=set('abc') z.add('san') z.update(set(['p', 'q'] ... ;, ‘c’, [‘p’, ‘q’], ‘san}...
asked Jan 2, 2023 in Technology by JackTerrance
0 votes
    What will be the output of the following Python program? def foo(x): x[0] = ['def'] x[1] = ['abc'] return id(x) q = ['abc ... (id(q) == foo(q)) a) Error b) None c) False d) True...
asked Jan 2, 2023 in Technology by JackTerrance
0 votes
    What will be the output of the following Python program? z=set('abc') z.add('san') z.update(set(['p', 'q'] ... ;, ‘c’, [‘p’, ‘q’], ‘san}...
asked Jan 2, 2023 in Technology by JackTerrance
0 votes
    What will be the output of the following Python program? def foo(x): x[0] = ['def'] x[1] = ['abc'] return id(x) q = ['abc ... (id(q) == foo(q)) a) Error b) None c) False d) True...
asked Jan 2, 2023 in Technology by JackTerrance
0 votes
    What is the output of the following program? 3 . #include using namespace std; struct Time { int hours; int ... 20000 D. O 15000 Select the correct answer from above options...
asked Dec 27, 2021 in Education by JackTerrance
0 votes
    What is the output of the following program? 3 . #include using namespace std; struct Time { int hours; int ... 20000 D. O 15000 Select the correct answer from above options...
asked Dec 26, 2021 in Education by JackTerrance
0 votes
    What will be the output of the following program? public class MyFirst { public static void main(String[ ... stackoverflow.com 🔗Source: Java Interview Questions and Answers...
asked Dec 19, 2020 in Technology by Editorial Staff
...