Quiz on Variables and Assignment Statements

This is a practice quiz. The results are not recorded anywhere and do not affect your grade. The questions on this quiz might not appear in any quiz or test that does count toward your grade.

Instructions: For each question, choose the single best answer. Make your choice by clicking on its button. You can change your answers at any time. When the quiz is graded, the correct answers will appear in the box after each question.



1. Which one of the following is a reserved word?

a. apple
b. 7up
c. grandTotal
d. boolean

2. Which one of the following is NOT a correct variable name?

a. 2bad
b. zero
c. theLastValueButOne
d. year2000

3. Which one of the following declarations is NOT correct?

a. double duty;
b. float loan = 84.6;
c. boolean value = 12;
d. int start = 34, end = 99;

4. What does the following program output?

class question4
{
  public static void main ( String[] args )
  {
    int unitCost = 8;    
    int items    = 5;
    System.out.println("total cost: " + (unitCost * items) );
  }
}
a. total cost: + 40
b. total cost: 8*5
c. total cost: 40
d. "total cost: " 40

5. Which of the following shows the syntax of an assignment statement?

a. variableName  =  expression;
b. expression  =  expression;
c. expression  =  variableName;
d. dataType  =  variableName;

6. What are the two steps that take place when an assignment statement is executed?

a. (i) Evaluate the Expression, and (ii) Store the value in the variable.
b. (i) Store the value in the variable, and (ii) Evaluate the Expression.
c. (i) Reserve memory , and (ii) fill it with a number.
d. (i) Evaluate the variable, and (ii) store the results.

7. What is an expression?

a. The same thing as a statement.
b. An expression is a list of statements that make up a program
c. An expression is a combination of literals, operators, variables, and parentheses used to calculate a value.
d. An expression is a number expressed in digits.

8. Which one of the following expressions is NOT correct?

a. 5 + 4
b. (5 * 4)/2
c. (-12 + (13 + 7)/2 ) * 4
d. -12 + (13 + 7)/2 ) * 4

9. Which of the following expressions is incorrect?

a. (34 - 86) / 3
b. (34 - 86) / -3
c. 34 - 86) / (23 - 3 )
d. ( (34 - 86) / (23 + 3 ) )

10. What is the value of the following expression:

(2 - 6) / 2 + 9

a. 7
b. 8
c. 9
d. 10

The number you got right:       Percent Correct:       Letter Grade:   

(If you have just returned here from another page, or re-loaded this page, you will need to click again on each of your choices for the grading program to work.)


Click here to go back to the main menu.