Test 1 Prep Questions Flashcards

1
Q

Is the following syntax legal or not legal:

double age = 3;

A

legal

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

A method header must not contain which of the following keywords:

a. ) static
b. ) void
c. ) method
d. ) private

A

c.)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the fundamental difference between the private and public members found in a class?

A

public: other classes can access
private: can only be accessed inside original class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is stored in a .class file generated by the Java compiler?

A

Java Virtual Machine (JVM) bytecode

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

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.

A

c.)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the resulting value and primitive type:

32.0 % 6

A

2.0

double

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the resulting value and primitive type:

(1/4 + 3.5) * 2.0

A

7.0

double

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the resulting value and primitive type:

3/2 + 2/3

A

1

int

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Rewrite the following for loop as an equivalent while loop:

for (int i = 0; i

A

int i = 0;

while (i

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

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);

A

c.)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly