Menu
Topics Index
...
`

Strings2059


If you need explanation Read this topic

If you need Answer Take test on this topic

Strings2059
What will be the output of following program?
public class Master {
    public static void main(String[] args) {
        String number1 = 50 + "";
        String number2 = 40 + "";
        String sum = "Sum";
        String first = number1.concat(number2);
        String second = first.concat(sum);
        second = second.concat(number1);
        second = second.concat(number2);
        System.out.print(second);
    }
}

A. 5040Sum5040
B. 90Sum90
C. 90Sum5040
D. Some other output
E. Compilation Error or Runtime Error
Topic: concat() method In Java

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

Answer is A,
It simply adds to right for every concat method and displays like 5040Sum5040.

Posted by Amar Kumar Biradar    2013-12-26 08:43:35


Answer is A,becoz concat method will add two strings..so,first=5040,second=5040sum,second=5040sum50 and finally second=5040sum5040 as output...every time it adds string right

Posted by Venkat Venky    2013-12-26 09:10:57


Congratulations Amar Kumar Biradar. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2013-12-27 03:54:22


Thanks Merit Campus :)
Got Recharge ;)

Posted by Amar Kumar Biradar    2013-12-27 16:42:56


© meritcampus 2019

All Rights Reserved.

Open In App