Free Practice Quiz Question List

5 Methods and Modular Design Online Quiz Questions

Use this free practice quiz with 20 questions to review 5 Methods and Modular Design, test your knowledge, and prepare for your next test or exam.

20 questions
01
True or false
1 point

True or false: A Java method declared with return type void may use return; to end execution early, but it cannot return a value.

  1. A

    True

  2. B

    False

02
Choose one
1 point

A program must calculate purchase totals in several places and may later change how totals are displayed. Which design best follows modular design?

  1. A

    Put input, tax calculation, printing, and receipt formatting into one long main method.

  2. B

    Create a method that calculates the purchase total and let the caller decide how to display it.

  3. C

    Create a method that calculates the total, prints it, formats a receipt, and saves a file.

  4. D

    Create a separate method for every individual arithmetic operator used in the calculation.

03
Written response
1 point

What Java term describes the situation in which a parameter named count hides a field also named count inside a method?

04
Fill in the blank
1 point

In a Java method declaration, the part that states what kind of value the method sends back is its .

05
Choose all
1 point

Which practices support good method design? Select all correct choices.

  1. A

    Give the method one main responsibility.

  2. B

    Use a meaningful name that communicates the method's purpose.

  3. C

    Make every method print its result immediately.

  4. D

    Return information that the caller may need.

06
True or false
1 point

True or false: If a Java method receives an array and assigns a new value to one of its elements, the caller can observe that element change after the method returns.

  1. A

    True

  2. B

    False

07
Choose one
1 point

In the following structure, where can blockVariable be referred to?

if (local > 0) { int blockVariable = 10; }

  1. A

    The variable is available throughout the class.

  2. B

    The variable is available throughout the containing method.

  3. C

    The variable is available only inside the if block where it is declared.

  4. D

    The variable is available only to the method's caller.

08
Written response
1 point

The method calculateTotal(40.00, 0.08) returns price + price * taxRate. What numeric value does the call return?

09
Fill in the blank
1 point

In a method call, the actual values supplied to the method's parameters are called .

10
Choose all
1 point

Which items are part of a useful method contract? Select all correct choices.

  1. A

    The purpose of the method.

  2. B

    The meaning and requirements of its inputs.

  3. C

    The exact names of every local variable used in the implementation.

  4. D

    The meaning of its output and any side effects.

11
Choose one
1 point

In the exam-score example, what is the primary responsibility of printReport(int[] scores)?

  1. A

    It replaces findAverage and findLetterGrade with one large calculation.

  2. B

    It coordinates the specialized methods and presents their results.

  3. C

    It modifies the scores array before each method call.

  4. D

    It determines which overloaded method the compiler must choose.

12
Open ended
1 point

A single method currently reads exam scores, calculates their total and average, assigns a letter grade, and prints a report. Explain how you would decompose this program into methods and what design considerations you would document.

13
Choose one
1 point

According to the supplied findAverage implementation, what does the method return when it receives an empty score array?

  1. A

    It throws an error because division by zero is unavoidable.

  2. B

    It returns the first score in the array.

  3. C

    It returns 0.0.

  4. D

    It returns NaN.

14
Choose one
1 point

Which statement best describes a Java method declared with the return type void?

  1. A

    It must return an int.

  2. B

    It performs an action without returning a value.

  3. C

    It can return any value without declaring a return type.

  4. D

    It can only be called from main.

15
Choose one
1 point

In the call square(6), what is 6?

  1. A

    The method name

  2. B

    The return value

  3. C

    The argument

  4. D

    The parameter declaration

16
Choose one
1 point

Why must absoluteValue return a compatible value in both the negative and nonnegative branches?

  1. A

    Only the branch containing the first return needs a value.

  2. B

    A non-void method may omit a return if its caller ignores the result.

  3. C

    Every possible execution path must return a compatible value.

  4. D

    Only methods returning boolean require a return statement.

17
Choose one
1 point

Why does calling changeFirstElement(values) change values[0] even though Java passes arguments by value?

  1. A

    The method receives the original reference variable, so all assignments affect the caller's variable.

  2. B

    The method receives a copied reference that still refers to the caller's array.

  3. C

    Arrays are passed by reference rather than by value in Java.

  4. D

    The method returns the changed array implicitly.

18
True or false
1 point

Inside setCount(int count), the parameter count shadows the field named count, so this.count refers to the object's field.

  1. A

    True

  2. B

    False

19
Written response
1 point

What design approach builds a program from small components that can be developed, tested, and reused independently?

20
Written response
1 point

What integer does countEven return for the array {3, 8, 10, 11}?