Java OCA OCP Practice Question 900

Question

What is the result of the following code?

StringBuilder b = "123456"; 
b.append(4).deleteCharAt(3).delete(3, b.length() - 1); 
System.out.println(b); 
  • A. 123
  • B. 1234
  • C. 12344
  • D. 1234564
  • E. An exception is thrown.
  • F. The code does not compile.


F.

Note

The first line does not compile because you cannot assign a String to a StringBuilder.

If that line were StringBuilder b = new StringBuilder("123456"), the code would compile.




PreviousNext

Related