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

Question 55


public class ArrayShortTest {

    public static void main(String[] args) {

        short[] numbers = new short[]{50, 50};

        numbers[0] = 5;

        numbers[1] = 10;

        System.out.println("[" + numbers[0] + ", " + numbers[1] + "]");

    }

}

What will be the result of compiling and executing the ArrayShortTest class?

  • A

    An exception is thrown at runtime

  • B

    [5, 10]

  • C

    Compilation Error

  • D

    [50, 50]

Reveal correct answer

Correct answer: C

Explanation

Declaring a local array with the name numbers conflicts with args in the same scope, leading to a compilation error due to the reuse of the parameter name args for a different variable in the same method.

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