• Post Reply Bookmark Topic Watch Topic
  • New Topic

Couldn't understand the output of an array program in HeadFirst Java  RSS feed

 
Arun KumarS
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I couldn't get how the first line of output comes as : null says Ruff!

I'm in learning stage(rookie :P)
Could someone explain how did it come?


 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since it sounds like you expected something else, why don't you start by telling us what you expected, and why. We'll chime in when you go off-track :-)
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


The Dog instance is created first. Since there is no constructor defined, a default constructor is created and each instance variable is given its default value. The default value of an object reference is null. bark is called which prints out the current value of the String.
 
Arun KumarS
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Ulf Dittmer : Sorry, I'm new to tis forum. I'l refine my ques and subj line next time.

@Keith Lynn : Yup. Didn't notice that. Thank you.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!