wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Java_Methods Quiz

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

Why do we use methods in Java?

a)

To make our code longer and complex

b)

To copy the same code multiple times

c)

To reuse, organize, and make code readable

d)

To avoid using classes

2.

What is the output of Math.pow(2, 3) in Java?

a)

6

b)

9

c)

8.0

d)

5.5

3.

What keyword is used in Java to indicate that a method does not return any value?

a)

null

b)

return

c)

empty

d)

void

4.

Which part of a method defines what inputs it needs?

a)

Method body

b)

Method return type

c)

Parameters

d)

Variables

5.

What is the term for calling a method from another method (e.g., main() calling greetUser())?

a)

Compiling

b)

Overriding

c)

Invoking

d)

Declaring

6.

What is the return type of this method: public static double calculateArea(double l, double w)?

a)

void

b)

int

c)

double

d)

String

7.

When does the return statement stop a method’s execution?

a)

Only at the end of the program

b)

When all variables are declared

c)

Immediately

d)

Never

8.

What’s the purpose of parameters in methods?

a)

To make the method longer

b)

To store return values

c)

To accept input values

d)

To print messages

9.

In the method signature public static int sum(int a, int b), what is int a?

a)

A return value

b)

A method call

c)

A parameter

d)

A loop

10.

What is the correct way to call the method greetUser() from main()?

a)

greetUser;

b)

main.greetUser();

c)

call greetUser();

d)

greetUser();