Test 1 Prep Questions Flashcards
Is the following syntax legal or not legal:
double age = 3;
legal
A method header must not contain which of the following keywords:
a. ) static
b. ) void
c. ) method
d. ) private
c.)
What is the fundamental difference between the private and public members found in a class?
public: other classes can access
private: can only be accessed inside original class
What is stored in a .class file generated by the Java compiler?
Java Virtual Machine (JVM) bytecode
Circle the letter matching the statement that is true about static variables.
a. ) A static variable may not be altered after its initial assignment except when keeping track of how many instances of its associated class have been created.
b. ) Static variables that are created within methods keep their values between method invocations.
c. ) A single instance of a static variable exists regardless of the number of instances of the associated class.
d. ) The static modifier cannot be used without a final modifier.
c.)
What is the resulting value and primitive type:
32.0 % 6
2.0
double
What is the resulting value and primitive type:
(1/4 + 3.5) * 2.0
7.0
double
What is the resulting value and primitive type:
3/2 + 2/3
1
int
Rewrite the following for loop as an equivalent while loop:
for (int i = 0; i
int i = 0;
while (i
Which of the following creates a die that produces the upper ranges of a regular 6-sided die (must have some randomness, gen is a Random object):
a. ) int faceValue = gen.nextInt(1) + 6;
b. ) int faceValue = gen.nextInt(4) + 2;
c. ) int faceValue = gen.nextInt(3) + 4;
d. ) int faceValue = gen.nextInt(6);
c.)