• Post Reply Bookmark Topic Watch Topic
  • New Topic

Head First Java Question Primitive Types page 51  RSS feed

 
Jim Brent
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I hate to ask this question but I am reading a side bar on Page 51 of Head First Java Second Edition and I don't understand a particular declaration with assignment. It is as follows:

boolean powerOn;

powerOn = isFun;

I don't understand how this is legal, if a boolean can only be true or false how is this valid? Wouldn't the only legal values for the powerOn variable be true or false?

Any help would be greatly appreciated.

Thank you.


 
Guillermo Ishi
Ranch Hand
Posts: 789
C++ Linux Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the book, the declarations are listed as follows

When line 4 is executed, isFun has already been declared and assigned a value. What line 4 is doing is assigning the value of the isFun variable to powerOn. This is legal; values assigned need not be literal values.
 
Guillermo Ishi
Ranch Hand
Posts: 789
C++ Linux Python
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The books always say it's fun, but sometimes it's just not.
 
Jim Brent
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you... Now I see it... I completed missed the assignment earlier in the sidebar...

So what the computer "sees" is the value "true" not isFun...

To re-state: The computer assigns the value "true" to to the powerOne variable, this is NOT a reference to the value held in the isFun variable - correct?

Thank you again...
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jim Brent wrote:
To re-state: The computer assigns the value "true" to to the powerOne variable, this is NOT a reference to the value held in the isFun variable - correct?

Correct. Since these variables are boolean, which is a primitive type, powerOne is assigned the same value that the isFun variable has at that point. No object references were involved in any of this.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!