The question is asking what should go in place of the [???] in order to make the assertion statement at the bottom succeed. I have figured out that the answer should be "Child String". However I don't understand why when calling name() on p while passing "String" as an argument results in the overridden method name(Object b) being called as opposed to the name method that specifically takes a string as an argument?
I understand that String extends Object (I think?) but I don't quite understand why this occurs.
The code is as follows:
interface Parent {
public String name(Object b);
}
class Child implements Parent {
public String name(Object b) {
return [???];
}
public String name(String b) {
return "Child " + [???];
}
}
public class Exercise {
public static void main(String[] args) {
Parent p = new Child();
assert p.name("String").equals("Child String");
}
}
Initially I thought p.name("String") would call "public String name(String b)" as the argument given to the name() method is specifically a String.