Your browser has JavaScript turned off. This page is best viewed with Javascript enabled. Certain functions on this site will not work, and some style sheets will not load. Check your browser preferences to enable JavaScript.

Teach Yourself Java

Lesson 2 Quiz

1. What is the main function of any variable?
To add numbers together
To keep track of data in the memory of the computer
To print words on the screen
To write Java

2. What is the proper way to declare a variable?
variableName variableType;
variableName;
variableType variableName;
variableType;

3. Booleans are _______.
All numbers
Single characters
Text
True or False

4. The following statements make “length” be what number?

int length;
length = 4;
length ++;
4
5
6
8

5. What is an assignment statement?
Adding a number to an int
Assigning a multiplication
Assigning a name to a variable
Assigning a value to a variable

6. What will be the value of “num” after the following statements?

int num;
num = (5+4);
num = num / 9;
num = 12;
0
1
9
12