I have an object object
and I'm going to call it's method toString
. How do I know in what exact class this method is implemented last?
For example if we have hierarchy:
class A /*extends Object */{
}
class B extends A{
public String toString() {
return "representation";
}
}
class C extends B{
}
class D extends C{
}
and the object
Object object = new SomeClass(); //(A/B/C/D/Object)
then for toString()
I should get Object
for Object
and A
but B
for B
, C
and D
someMethod()
? Where is the hierarchy? What doestoString()
have to do with anything?object
, you want to know (via reflection) whetherobject.toString()
would callB.toString()
orObject.toString()
?