• Post Reply Bookmark Topic Watch Topic
  • New Topic

Pg 62 Head First:Java queries.  RSS feed

 
WeiJie Lim
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


The end result is
null says Ruff!
last dog's name is Bart
Fred says Ruff!
Marge says Ruff!
Bart says Ruff!


Why does "null says Ruff!" even appear ?

And for the 2nd line, "last dog's name is Bart" , shouldn't "Bart" be printed on a different line due to println ?

thanks in advance =)
 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
WeiJie Lim wrote:Why does "null says Ruff!" even appear ?

What's the name of the first Dog you create? More specifically, what's its name when you call the method?

And for the 2nd line, "last dog's name is Bart" , shouldn't "Bart" be printed on a different line due to println ?

Look at the previous line.

Winston
 
WeiJie Lim
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Gutkowski wrote:
What's the name of the first Dog you create? More specifically, what's its name when you call the method?


Are you referring to the Class Dog at the very first line ? =X That particular Dog doesn't have a name..

Winston Gutkowski wrote:
Look at the previous line.

Winston


Still don't get it,sorry. The previous line is "System.out.print(“last dog’s name is “);" am I right ? It prints "last dog’s name is" normally, as for "Bart" it should jump to a new line ?

thinking about this got me confused about something else - why is "null says Ruff!" printed at the start.. as the command for it is below the command for "last dog's name" .

 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
WeiJie Lim wrote:Still don't get it,sorry. The previous line is "System.out.print(“last dog’s name is “);" am I right ? It prints "last dog’s name is" normally, as for "Bart" it should jump to a new line ?

You're using print() not println(), that's why it is printed in the same line.

WeiJie Lim wrote:thinking about this got me confused about something else - why is "null says Ruff!" printed at the start.. as the command for it is below the command for "last dog's name" .

You are invoking bark() method at line 6 of your code, that's why you get "null says Ruff" at the output. Printing "last dog's name..." is done at line 19-20.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!