wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Java Basics Quiz for CH/PT Students

Total questions: 16

Worksheet time: 5mins

Name
Class
Date
1.

What does System.out.println() do?

a)

Takes user input

b)

Outputs text to the console

c)

Ends a program

d)

None of the above

2.

Which keyword is used to define a class in Java?

a)

class

b)

define

c)

struct

d)

object

3.

What is the purpose of the public keyword in Java?

a)

It hides the method or class from other classes.

b)

It allows the method or class to be accessed from outside.

c)

It specifies that the method is private.

d)

None of the above.

4.

Which of the following is a correct way to declare a variable in Java?

a)

int 1x = 10;

b)

int x = 10;

c)

integer x = 10;

d)

num x = 10;

5.

Which data type is used to store a single character in Java?

a)

char

b)

String

c)

int

d)

boolean

6.

What will be the value of the variable z after executing the code below? int x = 5, y = 10; int z = x + y;

a)

5

b)

10

c)

15

d)

50

7.

What will be the result of the following code? int a = 10, b = 3; System.out.println(a % b);

a)

1

b)

3

c)

10

d)

0

8.

Which operator is used to increment a value by 1 in Java?

a)

--

b)

++

c)

+=

d)

**

9.

What does the != operator do in Java?

a)

Checks if two values are equal.

b)

Checks if two values are not equal.

c)

Assigns a value to a variable.

d)

Negates a Boolean value.

10.

Variables in Java must start with a letter or an underscore.

a)

TRUE

b)

FALSE

11.

Java uses double slashes (//) for multi-line comments.

a)

TRUE

b)

FALSE

12.

The main method is the entry point of a Java program.

a)

TRUE

b)

FALSE

13.

Which line of code will output the sum of 7 and 19?

a)

System.out.print(7 + 19);

b)

System.out.print("7 + 19");

c)

system.out.print(7 + 19);

d)

System.out.print(7 + 19)

14.

What is the extension of java code files?

a)

.class

b)

.java

c)

.txt

d)

.js

15.

What will be the output of this code?

class Codechef {

public static void main(String[] args) {

System.out.print(82);

System.out.print(2);

System.out.print(" 3");

} }

a)
A.82 2 3
b)
B.8223
c)
C.822 3
d)
D.822" "3
16.

What will be the output of this code?

class Codechef {

public static void main(String[] args) {

int a = 10 ;

int b = 3 ;

int c = a / b;

System.out.print(c); } }

a)

3.333

b)

3

c)

4

d)

a / b