wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Java-I-ch02_quiz01

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

What is a variable in Java?

a)
  • A) A storage location in memory

b)
  • B) A data type in Java

c)
  • C) A method that performs calculations

d)
  • D) A reserved word in Java

2.

Which of the following is a correct declaration of a variable in Java?

a)
  • A) int num = 100;

b)
  • B) 100 = int num;

c)
  • C) num int = 100;

d)
  • D) int 100 = num;

3.

What is the result of the following code?

a)

10

b)

20

c)

30

d)

40

4.

Which operator is used to find the remainder after division in Java?

a)

/

b)

#

c)

%

d)

++

5.
a)

3

b)

5

c)

8

d)

15

6.

Which data type should be used to store a number with a decimal in Java?

a)

int

b)

double

c)

char

d)

boolean

7.

What does the following code print?

a)

3

b)

3.3333

c)

3.0

d)

Error

8.

What is the result of the expression 10 % 3 in Java?

a)

0

b)

1

c)

2

d)

3

9.

What is the purpose of the ++ operator in Java?

a)
  • A) To add two variables

b)
  • B) To multiply a variable by 2

c)
  • C) To increment a variable by 1

d)
  • D) To perform a division operation

10.

Which of the following correctly initializes a variable num with the value 5 in Java?

a)
  • A) int num = 5;

b)
  • B) int num = "5";

c)
  • C) int num == 5;

d)
  • D) int num = '5';