What process helps with identifying the methods that make up a computer program? correct
answers Stepwise refinement
The term "Black Box" is used with methods because correct answers Only the specification
matters; the implementation is not important.
One advantage of designing methods as black boxes is: correct answers Many programmers can
work on the same project without knowing the internal implementation details of methods
After the keywords "public static", what are the names (in order) of the parts of this method
header?
public static int myFun (double a) correct answers Return type, method name, parameter variable
type, parameter variable type
Parameter variables should not be changed within the body of a method because? correct
answers It is confusing because it mixes the concept of a parameter with that of a variable.
What is the output of the following java program?
public class test01{
public static void main(String[] args){
for (int i = 0; i < 4; i++) { System.out.println(myFun(i) + " "); }
}
public static int myFun(int perfect) {
return ((perfect - 1) * (perfect - 1)); }
} correct answers 1 0 1 4
Which option represents a legal invocation of the method square?
public static String square(int a){
,return ("Commencing");
} correct answers String a = square(4);
What statement about the steps for implementing a method is true?
a) Pseudocode is the first step in the process for implementing a method
b) Pseudocode is the last step in the process for implementing a method
c) Unit testing (testing in isolation) of the implemented method is an important first step
d) Unit testing (testing in isolation) of the implemented method is an important final step correct
answers d
What is the problem with the code below?
public static String val() {
String result = "candy";
return;
}
...
// Using method val()System.out.println("The value is: " + val()); correct answers The method
val does not have a return value
What is the problem with the code snippet below?
public class test02{
public static void main(String[] args)
{
System.out.println(cost(10, 4));
}
,public static void cost(int price, int reps)
{
for (int i = 0; i < reps; i++)
{
System.out.print(price);
}
return;
}
} correct answers The method cost returns void and cannot be used as an expression in a print
statement
If a method is declared to return void, then which statement below is true?
a) The method cannot return until reaching the end of the method body
b) The method needs a return statement that always returns the integer value zero
c) When the method terminates no value will be returned
d) The method cannot be invoked unless it is in an assignment statement correct answers c
What is the purpose of a method that returns void? correct answers To package a repeated task as
a method even though the task does not yield a value
What is stepwise refinement? correct answers The process of breaking complex problems down
into smaller, manageable steps
Why is hand-tracing, or manually walking through the execution of a method, helpful? correct
answers It is an effective way to understand a method's subtle aspects
When hand-tracing methods, the values for the parameter variables correct answers Are
determined by the arguments supplied in the code that invokes the method
, A stub method is: correct answers A method that acts as a placeholder and returns a simple value
so another method can be tested
The variable name perfect in the method myFun in the code snippet below is used as both a
parameter variable and a variable in a nested block within the method. Which statement about
this situation is true?
public static int myFun(int perfect)
{
{
int perfect = 0;
return ((perfect - 1) * (perfect - 1));
}
} correct answers This multiple declaration of the variable perfect will not compile because the
scopes overlap
What is the output of the following java program?
public class test03
{
public static void main(String[] args)
{
for (int i = 0; i < 4; i++)
{
System.out.print(myFun(i) + "");
}
System.out.println(); }
public static int myFun(int perfect)
{