Answer:
The output is:
aaa 3
Step-by-step explanation:
Lets examine the code snippet
- public static void main(String[] args) {
- String[] arr = { "aaa", "bbb", "ccc" };
- mystery(arr);
- System.out.println(arr[0] + " " + arr.length);
- }
- public static void mystery(String[] arr) {
- arr = new String[5];
- arr[0] = "ddd";
- }
- }
Line 2 Creates an array with three string values
line 3 calls method mystery() The method definition on lines 6-9 indicates that it does not output any value, neither does it return any value
Line 4 determines the output of this code. In the output statement The first element of the array (indexed 0) is printed concatenated with the length of the array which is 3. Hence the output aaa 3