Java Pool Puzzle Polymorphism

I need help with this exercise. I have looked at the answer and still cant figure out how to to build the inheritance tree. I cant figure how the classes relate to each other can somebody explain. Please see attachment.

Did you work through the puzzle yourself? Or did you just jump to the answer?

If I were working through this problem I would work backwards and start with the System.out.println() method in main. I'd think about what statements would go into the sys out to achieve the required output format. Then work out how the data values get there, which leads to working out what classes are required and where.

Specifically which part don't you understand?

Tim Driven Development

Elim Banda

Ranch Hand

Posts: 46

posted 1 year ago

Tim Cooke wrote:Did you work through the puzzle yourself? Or did you just jump to the answer?

If I were working through this problem I would work backwards and start with the System.out.println() method in main. I'd think about what statements would go into the sys out to achieve the required output format. Then work out how the data values get there, which leads to working out what classes are required and where.

Specifically which part don't you understand?

I tried working through the puzzle but the I could not make sense of the inheritance because they are not logically linked together. How would you work this out step by step?

No, they aren't really logically linked together. And I think it is deliberate
You have to figure out the code snippets by the logic of the code, rather than trying to associate them to concepts in the real world.

Tim had some good advice about how you can figure out what each class is based on the number that got printed out.

I would add to that by looking at the lines of code in the pool. Which ones can you discount as obviously wrong? For instance the invocation of iMethod:

i.iMethod(X)
i(x).iMethod[]
i[x].iMethod()
i[x].iMethod[]

Only one of these is actually valid given the code above. Which? Put it in.

Elim Banda

Ranch Hand

Posts: 46

posted 1 year ago

Thanks these are the statements I was able to figure out as legitimate this is for the array so whats the next step?
i[x].iMethod[]
and i[x]