Menu
Topics Index
...
`

Strings2057


If you need explanation Read this topic

If you need Answer Take test on this topic

Strings2057
What will be the output of following program?
public class Additions {
    public static void main(String[] args) {
        String number = 50 + 40 + "Sum" + 50 + 40;
        String s = "Sum = ";
        System.out.println(s + number);
        String str = 50 + 40 + "";
        String srt = "Sum";
        System.out.printf(s, str.concat(srt));
    }
}

A. Sum = 90Sum90
Sum = 90Sum
B. Sum = 5040Sum5040
Sum = 5040Sum
C. Sum = 90Sum5040
Sum = 90Sum
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.

ans is E,bcoz println method accepts only one string as object.

Posted by Raviteja Daggupati    2013-12-25 04:13:31


D.some other output first SOP gives 90sum5040 and the next sop gives null

Posted by Shabaaz Shaikz    2013-12-25 04:34:22


D is the answer. First println statement prints "sum=90sum5040" and the second printf statement prints only the first argument's value i.e. "sum=".

Posted by Ramya Bonagiri    2013-12-25 04:51:30


C. because in first SOP prints "Sum=90Sum5040" and second SOP prints "Sum=90Sum

Posted by Shreenath Chandrakanth    2013-12-25 05:48:29


answer is 'E' because String objects are immutable in the above code we trying assign "sum" to str which already contains value...

Posted by Sai Teja    2013-12-25 09:13:46


Congratulations Ramya Bonagiri. You are this dose winner. We will send you the link using which you can claim your recharge.

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


Thank you @merit campus got the balance....????

Posted by Ramya Bonagiri    2013-12-26 11:21:47


© meritcampus 2019

All Rights Reserved.

Open In App