wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Methods Quiz

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

Suppose your method does not return any value, which of the following keywords can be used as a return type?

a)

void

b)

int

c)

double

d)

public

2.

The signature of a method consists of                         .

a)

method name

b)

method name and parameter list

c)

return type, method name, and parameter list

d)

parameter list

3.

When you invoke a method with a parameter, the value of the argument is passed to the parameter. This is referred to as          .

a)

method invocation

b)

pass by value

c)

pass by reference

d)

pass by name

4.

What is the correct syntax to declare a method named displayMessage that takes no parameters and returns nothing?

a)

public displayMessage()

b)

public void displayMessage()

c)

void displayMessage(void)

d)

function displayMessage()

5.

What is the purpose of the return statement in a method?

a)

To end a loop

b)

To exit the method and send a value back

c)

To define a variable

d)

To call another method

6.

Which of the following is NOT a valid method name in Java?

a)

getSum

b)

_findTotal

c)

2calculate

d)

computeAverage

7.

Which of the following statements correctly defines a method that receives an integer and returns a double?

a)

double calc(int x)

b)

void calc(double x)

c)

int calc(double x)

d)

calc(int x)

8.

What happens if a method specifies a return type but does not include a return statement?

a)

The compiler automatically returns zero

b)

The program runs normally

c)

A compile-time error occurs

d)

It returns null

9.

What is method overloading?

a)

Defining two or more methods with the same name but different parameter lists

b)

Using too many methods in one class

c)

Calling one method from another

d)

Writing a method that has too many parameters

10.

Which of the following statements about methods is true?

a)

A method can be called multiple times in a program

b)

Methods can only be used once

c)

Every method must return a value

d)

Methods cannot take parameters