1.Which of the following is false about a method that does not return a value? S
ID: 3710984 • Letter: 1
Question
1.Which of the following is false about a method that does not return a value?
Select one:
a. It can contain a return statement
b. It cannot be embedded in an expression
c. Its header must contain the keyword void
d. It can have 0 formal parameters
e. If you think none of the above are false, select this option
2. Which of the following is false about a method that does return a value?
Select one:
a. It must have formal parameters
b. Its header cannot contain the keyword void
c. It must be embedded in an expression for its return value to be used
d. All of its return statements must include an expression
e. If you think none of the above are false, select this option
3. Which of the following is false about this expression:
Math.max(Math.max(a, b), c)
You can assume a, b and c have been declared and have values of an appropriate type.
Select one:
a. It compiles
b. It does not cause a run time error
c. It returns the maximum value of a, b and c
d. The max method returns the same type as the type of its parameters
e. The inner max must complete execution before the outer max
f. If you think none of the above are false, select this option
Question 4
Question text
Consider the following expression that compiles:
methodA() && methodB()
What type does methodB return?
Select one:
a. Could be any type as long as it's the same as the type returned by methodA()
b. Any numeric type
c. boolean
d. String
e. Not enough information has been given to answer the question
Question 5
Question text
Which of the following is not required to create side effects?
Select one:
a. Actual parameter must be a variable
b. Formal parameter must be a reference type
c. A method must call a method
d. The called method must modify an object referenced by a formal parameter
e. If you think all of the above are required, select this option
Question 6
Question text
Which of the following cannot be an actual parameter under any circumstances?
Select one:
a. A literal
b. A constant
c. A variable
d. Any expression
e. A function call
f. If you think all of the above can be actual parameters, select this option
Question 7
Question text
Which of the following is a difference between the formal parameters and the local variables of a method?
You can assume all local variables are declared at the top of the method.
Select one:
a. Their scope
b. Their lifetime
c. Their initialisation
d. Their ability to remember previous lifetimes
e. If you think none of the above are a difference between the formal parameters and the local variables of a method, select this option
Question 8
Question text
Consider the following code carefully:
private void test01(){
int i, j;
i = 1; j = 2;
m1(i, j);
}
private void m1(int j, inti){
myWindow.writeOutLine(i);
}
What will be output when test01 executes?
Select one:
a. 1
b. 2
c. If you think the code will not compile, select this option
Question 9
Question text
Consider the following code:
private void test02(){
int [] i = {1, 2};
method2(i);
}
private void method2(int[] p){
myWindow.writeOutLine(i[1]);
}
What will be output when test02 executes?
Select one:
a. 1
b. 2
c. If you think the code will not compile, select this option
Question 10
Question text
Consider the following code:
private void test02(){
int [] i = {1, 2};
method2(i);
myWindow.writeOutLine(i[0]);
}
private void method2(int[] p){
//?
}
What needs to be coded in method2 to make the output statement in test02 display 2?
Select one:
a. i[0] = 2
b. p[0] = 2
c. i[0] = i[1]
d. p[0] = p[1]
e. If you think more than one of the above will produce the required output, select this option
Explanation / Answer
Question 1
Answer:
e. If you think none of the above are false, select this option
Question 2
Answer:
a. It must have formal parameters
Question 3
Answer:
d. The max method returns the same type as the type of its parameters
Question 4
Answer:
c. boolean
Question 5
Answer:
e. If you think all of the above are required, select this option
Question 6
Answer:
f. If you think all of the above can be actual parameters, select this option
Question 7
Answer:
a. Their scope
Question 8
Answer:
b. 2
Question 9
Answer:
b. 2
Question 10
Answer:
d. p[0] = p[1]
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.