• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Pool Puzzle Polymorphism  RSS feed

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Capture22.PNG
[Thumbnail for Capture22.PNG]
 
Marshal
Posts: 4052
239
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Elim Banda
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Bartender
Posts: 1840
10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!