wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Basic Java Quiz

Total questions: 15

Worksheet time: 5mins

Name
Class
Date
1.

What type of language is Java?

a)

Object Oriented

b)

Scripting

c)

Assembly

d)

Pseudocode

2.

What is the default value of an int variable in Java?

a)

0

b)

1

c)

null

d)

-1

3.

Which keyword is used to create an object in Java?

a)

create

b)

object

c)

new

d)

make

4.

What is the correct way to declare a variable of type double in Java?

a)

double variableName

b)

boolean variableName

c)

String variableName

d)

int variableName

5.

What is the output of the following code? int x = 5; System.out.println(x++);

a)

6

b)

null

c)

5

d)

4

6.

What is the output of the following code? String str = "Java"; System.out.println(str.length());

a)

6

b)

3

c)

5

d)

4

7.

What is the output of the following code? System.out.println(10 > 5 && 5 < 3);

a)

5

b)

true

c)

false

d)

10

8.

What is the correct way for storing WHOLE numbers in Java?

a)

float num = 5.0

b)

int num = 5;

c)

double num = 5.0

d)

string num = "5";

9.

What is the output of z?

int x = 5;

int y = 2;

int z = x/y;

a)

2.5

b)

2.50

c)

2

d)

ERROR

10.

Which of the loops is guaranteed to execute at least once?

a)

for loop

b)

while loop

c)

do-while loop

d)

enhanced while loop

11.

Which of the following is a valid way to make a comment in Java?

a)

#this is a comment

b)

"""This is a comment

c)

**This is a comment

d)

//This is a comment

12.

Which one is the proper format for a multi-line comment in Java?

a)

//

Hello

World

//

b)

*/

Hello

World

/*

c)

/*

Hello

World

*/

d)

There's no such thing

13.

What is the format for the main method in Java?

a)

public static void double(string[] args)

b)

public void static main(String[] args)

c)

private static void main(String[] args)

d)

public static void main(String[] args)

14.

Which of the following data types stores characters in Java?

a)

int

b)

double

c)

char

d)

boolean

15.

What is the output?

for (int i = 0; i < 3; i++) {

System.out.print(i + " ");

}

a)

0 1 2 3

b)

0 1 2 3 4

c)

0 1 2

d)

0 1