I was just wondering if I was missing anything for the following question. I’ve posed the question with my answer after it.
What kind of objects can be passed into the following method? What methods could be invoked on obj inside this method?
public void doThis (Object obj)
{
// some code
}
My answer:
The type of objects that can be passed in the above method are objects instantiated from actual classes that are super classes of the current class and also objects that have been instantiated in the current class itself. Additionally, objects that have been instantiated from other actual classes can be type casted into the current class or one of it’s super classes to be allowed as a parameter of the method doThis().
The methods that can be invoked inside the method include any public, protected, or private methods within the current class and any inherited methods from a superclass.
Is it correct?
Any subclass of
Object, includingObjectitself.Any public/protected method defined in the
Objectclass (e.g.toString,notify,wait, and etc.). This does not include methods defined in the subclass, unless you explicitly downcast.