• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Head First Object Exercise Chapter Two

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, I'm back. I took a Java course this spring at the local college, and learned enough to know I don't know what I'm doing. I'm now starting Head First Java with a study buddy. We're in Chapter Two - Objects, It's one of those complete the code from a list of "snippet" things. We chose different codes, yet have the same output. Neither of us can explain why we chose the differing snippets other than we worked it through our heads and this one worked. Can someone explain which of the coding is preferred and why? or does it matter and both are right.

Thanks

My Coding



His Coding



BTW -- My coding agrees with the book, so I assume his is wrong, but I can't show him why.

Thanks again
[ September 17, 2008: Message edited by: Richard Chambers ]
 
Sheriff
Posts: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The exercise was to fill in some gaps and get the code to print 10 right?
Then if both of you have used available code snippets, you are both right.

It just happens sometimes - there is not one correct answer, but multiple.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Add some println statements, and you will see the different behavior...

 
A day job? In an office? My worst nightmare! Comfort me tiny ad!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic