Oracle Certified Associate Java Se 8 Programmer · Free Practice Question Medium

Question 2

//ArrayProcessTest.java


public class ArrayProcessTest {

    public static void main(String[] args) {

        int[] arr = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};

        String str = process(arr, 3, 8); // Line 5

        System.out.println(str);

    }


    /*INSERT*/

}

Line 5 is giving a compilation error as the process method is not found. Which of the following method definitions, if used to replace /INSERT/, will resolve the compilation error?

  • A

    private static String process(int[] arr, int start, int end) {

    return null;

    }

  • B

    private static int process(int[] arr, int start, int end) {

    return null;

    }

  • C

    private static String[] process(int[] arr, int start, int end) {

    return null;

    }

  • D

    private static int[] process(int[] arr, int start, int end) {

    return null;

    }

Reveal correct answer

Correct answer: A

Explanation

It is clear from Line 5 that the method name should be process, it should be a static method, it should accept 3 parameters (int[], int, int), and its return type must be String.

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need