wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Topic 4 Quiz ITP

Total questions: 9

Worksheet time: 5mins

Name
Class
Date
1.

Which of the following is the correct syntax for a single-line comment in Java?

a)

#This is a comment

b)

// This is a comment

c)

/* This is a comment */

d)

<! - - This is a comment - ->

2.

What is the purpose of comments in Java code?

a)

To increase the execution speed of the program

b)

To provide explanations or annotations for the code

c)

To define variables

d)

To handle exceptions

3.

Which access modifier allows a member to be accessible only within its own class

a)

public

b)

protected

c)

private

d)

default

4.

If no access modifier is specifies for a class member, what is the default access level?

a)

public

b)

protected

c)

private

d)

package-private (default)

5.

What is a block in Java

a)

A single line of code

b)

A group of statements enclosed in braces {}

c)

A comment section

d)

A method declaration

6.

Which of the following is true about blocks in Java

a)

Blocks can be used to define the scope of variables

b)

Blocks are only used in loops

c)

Blocks are optional in method definitions

d)

Block cannot be nested

7.

Which of the following is the correct way to define a class in Java

a)

class Myclass { }

b)

public Myclass { }

c)

MyClass Class { }

d)

define class MyClass { }

8.

What is the purpose of class in Java

a)

To define a blueprint for objects

b)

To execute a block of code repeatedly

c)

To handle exceptions

d)

To perform arithmetic operations

9.

Why is the main method declared as static in Java

a)

To allow the JVM to invoke it without creating an instance of the class

b)

To enable method overloading

c)

To restrict its access to the class only

d)

To allow it to return a value