Java OCA OCP Practice Question 674

Question

Which of the following creates a StringBuilder with a different value than the other options?

  • A. new StringBuilder().append("clown")
  • B. new StringBuilder("clown")
  • C. new StringBuilder("cl").insert(2, "own")
  • D. All of them create the same value.


D.

Note

This question is testing whether you understand how method chaining works.

Option A creates an empty StringBuilder and then adds the five characters in clown to it.

Option B simply creates the clown when calling the constructor.

Option C creates the same value, just in two parts.

Option D is correct.




PreviousNext

Related