wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Topic 8-2: Method

Total questions: 9

Worksheet time: 8mins

Name
Class
Date
1.

Write a method header to return a square root of a number

a)

public static void double sqrt(value)

b)

public static void double sqrt(double value)

c)

public static double sqrt(value)

d)

public static double sqrt(double value)

2.

Write a method header to test whether a number is even, and returns true if it is

a)

public static boolean isEven(int value)

b)

public static void isEven(int value)

c)

public static int isEven(int value)

d)

public static void boolean (int value)

3.

Can we use "void" and "return" together?

a)

Yes

b)

No

4.

How many values can a method return?

a)

0

b)

1

c)

2

d)

infinite

5.

Which of these is a method with four parameters?

a)

public void math(int a, int b)

b)

public void math(double a, double b, double c, double d)

c)

public void math(a, b, c, d)

d)

public void math(4, 3, 2, 1)

6.

What is the output of this code?

a)

Error

b)

Hi Adila (12345)

c)

Adila 12345

d)

display

7.

What is the error in this code?

a)

No error

b)

Incorrect method header - public static String getSentence

c)

Parameters arrangement in getSentence(id, name)

d)

return statement

8.

Fix the error by replacing with the correct java statement.

a)

public static String getSentence(int id, String name)

b)

public static String getSentence(String name, int id)

c)

public static void getSentence(String name, int id)

d)

public static int getSentence(int id, String name)

9.

What is the output of this code?

a)

Error

b)

Second method

c)

Third method

d)

Hi Adila (12345)