WorksheetsChapter 6 - Boolean Expressions
Total questions: 12
Worksheet time: 3mins
Which of the following is NOT a relational operator?
!=
>=
/=
<=
Which of the following is NOT a logical operator?
!
==
&&
||
a || b is true if and only if either a is true or b is true, but not both.
true
false
Which of the following operators cannot be applied to boolean variables?
||
!=
>=
==
Given
String str1, str2;
What does str1 < str2 compare?
The addresses of the strings
The lengths of the strings
The contents of the strings in lexicographic order (as in a dictionary)
Nothing: this is not allowed in Java syntax
What is the value of x after the following code is executed?
0
1
2
4
A cohesive class represents a single concept, and all its constructors and public methods are related to that concept.
True
False
In a good design, coupling should be maximized.
True
False
Which of the following statements sets numDots to a random number between 1 and 6?
numDots = Math.randomInt(6);
numDots = Math.randomInt(6) + 1;
numDots = (int)(6 * Math.random());
numDots = (int)(6 * Math.random()) + 1;
Suppose
private enum Level {EASY, MEDIUM, HARD};
is properly defined in a class. Which of the following is a valid statement in that class’s constructor:
Level difficulty = EASY;
Level difficulty = enum Level(EASY);
Level difficulty = Level.HARD;
Level difficulty = HARD.Level;
Which of the following correctly defines a "stub class"?
A class where all methods are static
A temporary simplified version of a class used for testing other classes
A temporary class that implements GUI but has no real functionality behind it
A class with no constructors and only two public methods, getValue and setValue
Values of an enum type can be compared using < and > operators.
True
False
