Instructional Material: Variable Assignment Quiz Answers

Content: 

1. We have not declared variable a. Line 1 would generate a compiler error.

1a. Declaration creates a variable with it's data type and allocates appropriate memory space based on the data type. A variable must be declared before it's first use. Initialization is assigning a starting value to a newly created variable.

2. Only a single variable can appear left of the assignment ( = ) operator.

3. a = 7, b = 9.

4. a = 7, b = 9, c = 63.

5. a = 7, b = 63, c= 63.

6. a = 63, b = 63, c = 63.

7. a = 63, b = 63, c = 5.

8. The student thinks the definition of c has been permanently changed by line 8 to be b * a. c is a simple integer variable and only contains the numeric value assigned to it. The result of line 8 is c = 63.

9. A compiler error due to the fact we are trying to assign a floating point number to an integer. The Java compiler can't convert the float to an integer without loss of accuracy.

10. The same compiler error for the same reason.

 

Navigation: