wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

2.3-4-5 Calling a (non-)Void Method (with Parameters)

Total questions: 14

Worksheet time: 7mins

Name
Class
Date
1.

Which of the following is a correctly written method for the class on the left?

a)

b)

c)

d)

2.

Which of the following correctly calls the method addFiveMinutes on an object of the Timer class called kitchenTimer?

a)

kitchenTimer(addFiveMinutes);

b)

Timer.addFiveMinutes();

c)

kitchenTimer.addFiveMinutes();

d)

kitchenTimer.addFiveMinutes;

3.

Suppose the class Timer has a method called startTime that prints out the starting time of the Timer.
Which of the following correctly uses this method to print out the start time of a Timer object called laundry?

a)

System.out.println(laundry.startTime());

b)

System.out.println(laundry.startTime);

c)

int start = laundry.startTime();

d)

laundry.startTime();

e)

laundry.startTime;

4.

A Timer class is a class that represents a minute timer. A partial definition of the class is given on the left.

a)

The timer will end in 30 minutes

b)

The timer will end in 30 minutes

The timer will end in 35 minutes

c)

The timer will end in 30 minutes

The timer will end in 30 minutes

d)

This method won’t print anything because it doesn’t have any print statements.

5.

What are parameters?

a)

The value that a method returns.

b)


The values that a method prints to the screen.

c)

The formal names given to the data that gets passed into a method.

d)

The type that is given to a variable.

6.

Consider the Circle class on the left.

a)

24.0

20.0

b)

24.0

24.0

c)


Nothing will print because the code contains an error.

d)

24.0

7.

Consider the class on the left:

If a new variable Rectangle shape = new Rectangle(10, 20); was initialized, what is the correct syntax for retrieving the area of shape?

a)

int area = Rectangle.getArea();

b)

int area = shape.getArea();

c)

shape.getArea(10,20);

d)

Rectangle.getHeight() * Rectangle.getWidth();

e)

shape.getArea();

8.

Which of the following methods is implemented correctly with respect to the method’s return type?

a)

public String getColor()

{

return "Red";

}

b)

public int getColor()

{

return "Red";

}

c)

public void getColor()

{

return "Red";

}

d)

public Color()

{

return "Red";

}

9.

Suppose you have a class called Elevator. The Elevator class has a method called goingUp, partially defined on the left.

Which of the following statements correctly stores the return value of goingUp when it is called on the Elevator object called hotel?

a)

int up = hotel.goingUp();

b)

double up = hotel.goingUp();

c)

boolean up = hotel.goingUp();

d)

String up = hotel.goingUp();

10.

Suppose there is a class called Student. One of the methods is given below. It sets the instance variable isHonors to the parameter value.

Using the Student object called karel, which of the following is the correct way to set karel’s honor status to true?

a)

karel.setHonorStatus(isHonors = true);

b)

karel.isHonors = true;

c)

karel.setHonorStatus(status=true);

d)

karel.setHonorStatus(true);

11.

The value that a method outputs is called

a)

a print statement.

b)

an argument.

c)

a parameter.

d)


a return value.

12.

Consider the class on the left:

If a new variable Rectangle shape = new Rectangle(10, 20); was initialized, what is the correct syntax for retrieving the area of shape?

a)

int area = Rectangle.getArea();

b)

int area = shape.getArea();

c)

shape.getArea(10,20);

d)

Rectangle.getHeight() * Rectangle.getWidth();

e)

shape.getArea();

13.

Suppose you have a class called Elevator. The Elevator class has a method called goingUp, partially defined on the left.

Which of the following statements correctly stores the return value of goingUp when it is called on the Elevator object called hotel?

a)

int up = hotel.goingUp();

b)

double up = hotel.goingUp();

c)

boolean up = hotel.goingUp();

d)


String up = hotel.goingUp();

14.

Which of the following methods is implemented correctly with respect to the method’s return type?

a)

public String getColor() {

return "Red";

}

b)

public int getColor()

{

return "Red";

}

c)

public void getColor()

{

return "Red";

}

d)

public Color()

{

return "Red";

}