11. If a method is declared to return void, then which statement below is true?
ID: 3680051 • Letter: 1
Question
11.
If a method is declared to return void, then which statement below is true?
Select one:
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
12.
Which of the following method declarations would be appropriate for a method that compares 2 numbers?
The method body is shown here:
Select one:
a. public static void compare(int num1, int num2)
b. public static int compare(int num1, int num2)
c. public static boolean compare(int num1, int num2)
d. public static double compare(int num1, int num2)
13.
Which statement about the steps for implementing a method is true?
Select one:
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
14.
Given the following code, what is the output?
Select one:
a. ABCd
b. 4531
c. 45&*
d. 45
15.
Given the following code, which argument(s) will cause the method to return true?
I. isIdeal("civic")
II. isIdeal("level")
III. isIdeal("race car")
IV. isIdeal("rotor")
Select one:
a. I only
b. I and II only
c. I, II, and III
d. I, II, and IV
16.
Why is hand-tracing, or manually walking through the execution of a method, helpful?
Select one:
a. It is an effective way to understand a method’s subtle aspects
b. It guarantees that the method will compile without errors
c. It makes unit testing unnecessary
d. It enforces the “black-box” concept of method design
Explanation / Answer
Answer:
11.
If a method is declared to return void, then which statement below is
true?
Select one:
Option C is correct answer i.e-----------> c. When the method terminates no value will be returned
12)
Which of the following method declarations would be appropriate for a
method that compares 2 numbers?
The method body is shown here:
{
return num1 > num2;
}
Select one:
Option C is correct answer i.e --------------------->c. public static boolean compare(int num1, int num2)
13.
Which statement about the steps for implementing a method is true?
Select one:
Option d is correct answer i.e ----------->d. Unit testing (testing in isolation) of the implemented method is an important final step
14)
Given the following code, what is the output?
public static String magic(String s)
{
String r = "";
boolean got = false;
for (int i = 0; i < s.length(); i++)
{
if (Character.isDigit(s.charAt(i)))
{
r = r + s.charAt(i);
got = true;
}
else if (got)
{
return r;
}
}
return r;
}
public static void main(String[] args)
{
System.out.println(magic("ABCd45&*31"));
}
Select one:
Option d is correct answer i.e--------------------------> 45
15.
Given the following code, which argument(s) will cause the method to
return true?
publicstatic boolean isIdeal(String s)
{
int low = 0;
int high = s.length() - 1;
while (low < high)
{
if (s.charAt(low) != s.charAt(high))
{
return false;
}
low++;
high--;
}
return true;
}
I. isIdeal("civic")
II. isIdeal("level")
III. isIdeal("race car")
IV. isIdeal("rotor")
Select one:
a. I only
b. I and II only
c. I, II, and III
d. I, II, and IV
Option d is correct answer i.e ------------------>d. I, II, and IV (I. isIdeal("civic"),II , isIdeal("level") and III.isIdeal("rotor") )
16
Why is hand-tracing, or manually walking through the execution of a method, helpful?
Select one:
Option c is correct answer i.e -------------------->c. It makes unit testing unnecessary
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.