This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Pool Puzzle - TestBoats Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Pool Puzzle - TestBoats" Watch "Pool Puzzle - TestBoats" New topic
Author

Pool Puzzle - TestBoats

Eddie Davis
Greenhorn

Joined: Jul 31, 2009
Posts: 16
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!






Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29275
    
140

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


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Eddie Davis
Greenhorn

Joined: Jul 31, 2009
Posts: 16
Jeanne I see it now! Thank you for going to the trouble of explaining this to me. Mucho appreciated!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Pool Puzzle - TestBoats
 
Similar Threads
question about assertion
Assignment Operator and wrappers
Why will class compile but public class will not compile?
how to compile java source code with assertion ?
Puzzle