What will be written to the standard output when the following program is run?
public class Main{ public static void main (String args []){ String blank = " "; // one space String line = blank + "hello" + blank + blank; line.concat ("world"); String newLine = line.trim (); System.out.println ((int)(line.length () + newLine.length ())); } }
Select 1 option
Correct Option is : E
Note that line.concat("world") does not change line itself.
It creates a new String object containing " hello world " but it is lost because there is no reference to it.
Calling trim()
does not change the object itself.
So the answer is 8 + 5 = 13 !