I'm studying the book OCA/OCP
Java SE 8 Programmer Practice Tests, by Scott Selikoff and Jeanne Boyarsky. The question 46 at chapter 9 states the following:
46. 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
And the answer is the following:
D.
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.
The question asks for the types that can be passed for replace() method on the
String class. The String class only have the following versions of the replace method:
public String replace(char oldChar, char newChar)
public String replace(CharSequence target, CharSequence replacement)
So far so good, this is contemplated by the answer. However, why String and StringBuider are considered valid, once there isn't a method that takes them as parameter. I couldn't really understand what "Both String and StringBuilder implement this interface" has to do with it.