• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java Pool Puzzle Polymorphism

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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]
 
Sheriff
Posts: 5555
326
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1845
10
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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]
 
reply
    Bookmark Topic Watch Topic
  • New Topic