Professional Documents
Culture Documents
Date:
Section:
1. Which of the following is a proper way to declare and initialize a variable in Java?
A. myInteger = 100;
B. char = 'a';
D. "Variable"
final int z;
z = 20;
z = 30;
System.out.println(z);
A. 20
B. 30
C. This code gives an error.
D. Nothing is printed.
3. What are the memory values associated with the variables x, y, and z after the code snippet below executes?
int x = 7;
double y = 2.0;
boolean z = false;
x = x + 3;
z = true;
A. x holds the int value 7, y holds the double value 2.0 and z holds the boolean value false .
B. x holds the int value 10, y holds the double value 2.0 and z holds the boolean value true .
4. Which of the following variable names follows best practices for naming a variable?
A. 5apples
B. someVariable
C. applesnum
D. numApples
5. What does the keyword final do?
6. Which Java Data Type would be the best suited to represent whether or not a student has completed their homework?
A. int
B. double
C. String
D. boolean
7. Which Java Data Type would be best suited to represent the amount of money in a bank account?
A. double
B. boolean
C. int
D. String
8. Which Java Data Type would be the best suited to represent the number of days left until the AP Computer Science
Exam?
A. double
B. String
C. int
D. boolean