Java OCA OCP Practice Question 1879

Question

What will the following code print?

String abc = "";
abc.concat ("abc");
abc.concat ("def");
System.out.print (abc);

Select 1 option

A. abc
B. abcdef
C. def
D. It will print empty string (or in other words, nothing).
E. It will not compile because there is no concat() method in String class.


Correct Option is  : D

Note

Strings are immutable so doing abc.concat("abc") will create a new string "abc" but will not affect the original string "".




PreviousNext

Related