Java OCA OCP Practice Question 754

Question

Which of the following types can you pass as a parameter to the replace() method on the String class?

  • I. char
  • II. String
  • III. StringBuilder
  • A. I
  • B. I and II
  • C. II and III
  • D. I, II, and III


D.

Note

There are two signatures for the replace() method. One takes two char parameters.

The other signature takes a CharSequence.

Both String and StringBuilder implement this interface.

This makes all three alternatives correct, and Option D is correct.




PreviousNext

Related