05.0 Java Notes‎ > ‎

Java: Assignment Statment

The assignment statement:
  • assigns a value to a variable
  • is used to assign a memory location to a variable
  • you can tell the assignment statement by the single equal sign =
  • the value and the variable must be of the same data type
  • the variable on the left is being changed to the value on the left
  • it is often confused with the comparison operator == which will compare two values and check to see if they are the same

Examples:
 Java Statementreads as 
age = 16;age is assigned the value of 16
age = age +1;increase the age by 1        
 age ++;increase the age by 1
isReady = true;isReady is assign the value of true
playAgain = (reply == "y"); playAgain is assigned the value of the comparison of the variable reply and the letter y
note:  if the reply is a y the value will be true, otherwise it will be false.
 Balloon balloon = new Balloon();create a new instance of the Balloon class location in memory called balloon, that will point to a Balloon using the constructor Balloon( )



Comments