You are asked to create a method that accepts an array of integers and returns the highest value from that
array.
Given the code fragment:
Which method signature do you use at line n1?
A.
public int findMax (int [] numbers)
B.
static int[] findMax (int max)
C.
static int findMax (int [] numbers)
D.
final int findMax (int [] )
Test B
Answer is C
A.public int findMax (int [] numbers)// non-static method findMax(int[]) cannot be referenced from a static context
B.static int[] findMax (int max)// incompatible types: int[] cannot be converted to int
C.static int findMax (int [] numbers)//ok
D.final int findMax (int [] )// Check class headers… parsing individual files failed!
Answer is C:
package q020;
public class Test {
public static void main(String[] args) {
int[] numbers = {12, 13, 42, 32, 15, 156, 23, 51, 12};
int max = findMax(numbers);
}
static int findMax (int[] numbers) { /* line n1 */
int max = 0;
System.out.println(“Answer c”);
/* code goes here */
return max;
}
}
C
C. because method is be called from static method.
C