wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Chapter 6 - Boolean Expressions

Total questions: 12

Worksheet time: 3mins

Name
Class
Date
1.

Which of the following is NOT a relational operator?

a)

!=

b)

>=

c)

/=

d)

<=

2.

Which of the following is NOT a logical operator?

a)

!

b)

==

c)

&&

d)

||

3.

a || b is true if and only if either a is true or b is true, but not both.

a)

true

b)

false

4.

Which of the following operators cannot be applied to boolean variables?

a)

||

b)

!=

c)

>=

d)

==

5.

Given


String str1, str2;


What does str1 < str2 compare?

a)

The addresses of the strings

b)

The lengths of the strings

c)

The contents of the strings in lexicographic order (as in a dictionary)

d)

Nothing: this is not allowed in Java syntax

6.

What is the value of x after the following code is executed?

a)

0

b)

1

c)

2

d)

4

7.

A cohesive class represents a single concept, and all its constructors and public methods are related to that concept.

a)

True

b)

False

8.

In a good design, coupling should be maximized.

a)

True

b)

False

9.

Which of the following statements sets numDots to a random number between 1 and 6?

a)

numDots = Math.randomInt(6);

b)

numDots = Math.randomInt(6) + 1;

c)

numDots = (int)(6 * Math.random());

d)

numDots = (int)(6 * Math.random()) + 1;

10.

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:

a)

Level difficulty = EASY;

b)

Level difficulty = enum Level(EASY);

c)

Level difficulty = Level.HARD;

d)

Level difficulty = HARD.Level;

11.

Which of the following correctly defines a "stub class"?

a)

A class where all methods are static

b)

A temporary simplified version of a class used for testing other classes

c)

A temporary class that implements GUI but has no real functionality behind it

d)

A class with no constructors and only two public methods, getValue and setValue

12.

Values of an enum type can be compared using < and > operators.

a)

True

b)

False