I know this is old, but it appeared in a project I was working on recently (only the junior developer is doing something unexpected - there was no real reason for this!), And I think some of the answers missed the point ..
This has nothing to do with normal polymorphism; I think the question relates to the case where the code looks like this:
class A {
B b;
}
class B extends A {
}
. , - , , , , Java, . Object.
, , Object String toString , String Object.
, , , , .
.
class A {
B b;
A(){
b = new B();
}
}
class B extends A {
}
- , , B , B ..