File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Head First Java Book question

 
Rob Willmann
Greenhorn
Posts: 1
Debian MySQL Database VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greetings all!

I am totally new to Java, and am working through the "Head First" Java book, 2nd ed.

On p. 39 there's a class code example called GuessGame.

Right off the bat, the code looks like this:



My question is as follows.

There's another class called Player, which creates Player object instances.

the GuessGame class creates the Player Object by calling them via:

p1 = new Player();

Why did we need to put the Player p1 code lines at the top?

Couldn't the Guess game have called them by:

?

Thanks!

rob
 
shivang sarawagi
Ranch Hand
Posts: 155
  • 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Player p1 is given to make p1 as an instance variable of the class
if you give this within a method this becomes a local variable whose scope is limited within
the method.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic