The question is:
Suppose o is a reference of type Object that is pointing to a type A object that contains a f method and a toString method. Both toString and f have no parameters. show the statement that calls the toString method and the statement that calls the f method.
is the answer:
f();
toString();
No, that’s not right. First of all, you’re not using the instance
oto invoke the methods. Without specifying an instance the compiler would cause those methods to be implicitly called onthis.Second, you can’t invoke
o.f()sincefis not a method ofObject. An explicit cast is required to tell the compiler thatois of typeA.See Also