Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Pg 62 Head First:Java queries.

 
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 =)
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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" .

 
Bartender
Posts: 825
5
Python Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
We find this kind of rampant individuality very disturbing. But not this tiny ad:
The trailboss has a kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic