wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Java Chapter 2 Review Questions

Total questions: 22

Worksheet time: 12mins

Name
Class
Date
1.

Every complete statement ends with a:

a)

period

b)

parenthesis

c)

semicolon

d)

ending brace

2.

The following data
72
'A'
"Hello World"
2.8712

are all examples of:

a)

variables

b)

literals

c)

strings

d)

none of these

3.

A group of statements, such as the contents of a class or a method, are enclosed in

a)

braces {}

b)

parentheses ()

c)

brackets []

d)

any of these will do

4.

Which of the following are not valid assignment statements?
(include all that apply)

a)

total = 9;

b)

72 = amount;

c)

profit = 129

d)

letter = 'W';

5.

Which of the following are not valid println statements?
(Indicate all that apply.)

a)

System.out.println + "Hello World";

b)

System.out.println("Have a nice day");

c)

out.System.println(value);

d)

println.out(Programming is great fun);

6.

The negation operator is

a)

unary

b)

binary

c)

ternary

d)

none of these

7.

This keyword is used to declare a named constant.

a)

constant

b)

namedConstant

c)

final

d)

concrete

8.

These characters mark the beginning of a multi-line comment

a)

//

b)

/*

c)

*/

d)

/**

9.

These characters mark the beginning of a single-line comment

a)

//

b)

/*

c)

*/

d)

/**

10.

These characters mark the beginning of a documentation comment

a)

//

b)

/*

c)

*/

d)

/**

11.

Which Scanner class method would you use to read a string as input?

a)

nextString

b)

nextLine

c)

readString

d)

getLine

12.

Which Scanner class method would you use to read a double as input?

a)

nextDouble

b)

getDouble

c)

readDouble

d)

None of these; you cannot read a double with the Scanner class

13.

If you use this keyword to declare a local variable, you do not have to specify the variable's data type.

a)

var

b)

type

c)

auto

d)

local

14.

When Java converts a lower-ranked value to a higher-ranked type it is call a(n)

a)

4-bit conversion

b)

escalating conversion

c)

widening conversion

d)

narrowing conversion

15.

This type of operator lets you manually convert a value, even if it means that a narrowing conversion will take place.

a)

cast

b)

binary

c)

uploading

d)

dot

16.

A left brace in a Java program is always followed by a right brace later in the program.

a)

True

b)

False

17.

A variable must be declared before it can be used.

a)

True

b)

False

18.

Variable names may begin with a number

a)

True

b)

False

19.

You cannot change the value of a variable whose declaration uses the final keyword

a)

True

b)

False

20.

Comments that begin with // can be processed by javadoc

a)

True

b)

False

21.

If one of an operator's operands is a double, and the other operand is an int, Java will automatically convert the value of the double to an int

a)

True

b)

False

22.

If you use the var keyword to declare a variable, you cannot initialize the variable with a value

a)

True

b)

False