• 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

Pool Puzzle - TestBoats

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In Head First Java Chapter 7 there is a puzzle where you're to add missing parts of the code to get it to compile which will then give the print result - "drift drift hoist sail " I have the proper code but I'm having trouble walking through the code to see how it prints out "drift drift hoist sail"

There is one system.print.out that is "stroke natasha" but it doesn't get printed. The code is below. Could someone tell me how this works?

Thanks!






 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Boat b1 = new Boat();
Sailboat b2 = new Sailboat();
Rowboat b3 = new Rowboat();
b2.setLength(32);
b1.move(); // prints "drift" because calls the Boat classes move method
b3.move(); // prints "drift" because calls the Boat classes move method (While we have a RowBoat, it doesn't have a move
method and inherits the superclass Boat's one)
b2.move(); // prints "hoist sale" because calls the Sailboat's move method. Since it has its own, the superclass Boat's move method doesn't get called
 
Eddie Davis
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jeanne I see it now! Thank you for going to the trouble of explaining this to me. Mucho appreciated!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic