Courseiva

1Z0-811 · domain

Arrays and Methods

Practise Oracle Java Foundations 1Z0-811 Arrays and Methods practice questions — original exam-style scenarios with answer choices, explanations, and analysis of common mistakes.

75 questions24 easy28 medium23 hard

Focused practice

Practice Arrays and Methods questions

Scored sessions drawing only from this domain — pick a length below.

Start 20-question practice test →

What this domain covers

What to know about Arrays and Methods

Arrays and Methods questions test whether you can apply the concept in context, not just recognise a definition.

How the topic appears in realistic exam-style scenarios.

Which detail in the question changes the correct answer.

How to eliminate plausible but wrong options.

How to connect the question back to the wider exam objective.

Watch out for

Common Arrays and Methods exam traps

  • Answering from memory before reading the full scenario.
  • Missing a constraint such as cost, availability, security, scope or command context.
  • Choosing a broad answer when the question asks for the most specific fix.
  • Ignoring why the wrong options are tempting.

Question index

All Arrays and Methods questions (75)

Click any question to see the full explanation, or start a practice session above.

1

A method 'public static void sort(int[] arr)' sorts the array in place. After calling 'sort(data)', the original array 'data' is changed. Which design issue does this demonstrate?

Medium
2

What is the output?

Medium
3

Which TWO are valid ways to pass an array to a method in Java?

Medium
4

Which TWO statements are true about method overloading in Java?

Easy
5

What is the output?

Medium
6

Given the array declaration: int[] data = new int[5];, what is the value of data[2] after initialization?

Easy
7

Which three statements about method overloading are true? (Select three.)

Medium
8

Consider the following code that attempts to swap the first two elements of an array using a method: public static void swap(int[] arr) { int temp = arr[0]; arr[0] = arr[1]; arr[1] = temp; } public static void main(String[] args) { int[] values = {1, 2}; swap(values); System.out.println(values[0] + " " + values[1]); } What is the output?

Easy
9

Given the method: 'public static void swapFirstTwo(int[] arr) { int temp = arr[0]; arr[0] = arr[1]; arr[1] = temp; }'. What is the effect of calling this method with an array of length 1?

Hard
10

What is the output when the main method is executed? ```java public class Test { public static double add(double a, double b) { return a + b; } public static void main(String[] args) { System.out.println(add(5, 10)); } } ```

Easy
11

Which statement about method overloading with array parameters is true?

Hard
12

Which TWO are valid ways to declare and initialize an array of Strings?

Easy
13

Given an array arr of length 5, which code snippet correctly creates a copy using System.arraycopy?

Easy
14

A method 'public static int[] generate() { int[] result = new int[10]; for (int i = 0; i < result.length; i++) result[i] = i * 2; return result; }' is defined. Which statement correctly calls this method and stores the result?

Hard
15

Given the code: public class Test { public static void change(int[] arr) { arr = new int[]{10, 20}; } public static void main(String[] args) { int[] arr = {1, 2}; change(arr); System.out.println(arr[0]); } } What is the output?

Hard
16

Which approach does NOT create a new array that is independent of the original?

Hard
17

Which two of the following are valid ways to declare and initialize an array of integers? (Select two.)

Easy
18

Which of the following is not a valid array variable declaration in Java?

Easy
19

A method is needed to return a new array where each element is doubled. Which method signature correctly accomplishes this?

Easy
20

A company manages employee data stored in an array of Employee objects. The HR application frequently needs to find an employee by ID. The current implementation uses a linear search through the array each time. Performance reports indicate that this search is becoming a bottleneck as the company grows. The array is not sorted, and the company does not want to sort it because the order is meaningful for display. The array is large and frequently updated. The development team considers several options to improve the search performance without changing the array order. Which approach should they implement?

Medium
21

Given the code: int[] a = {1, 2, 3}; int[] b = {4, 5}; a = b; b[0] = 99; System.out.println(a[0]); What is the output?

Medium
22

Which TWO methods correctly modify the passed array in place?

Medium
23

Which THREE statements are true about passing arrays to methods in Java?

Hard
24

A developer writes a method that accepts a variable number of int arguments and returns their product. Which method signature correctly implements this?

Medium
25

A developer writes two methods: public void process(int a) { ... } and public void process(double a) { ... }. Which method is called by process(10)?

Medium
26

What is the output?

Hard
27

Given the code snippet: 'int[] nums = {10, 20, 30, 40}; int sum = 0; for (int i = 0; i < nums.length; i++) { sum += nums[i]; }'. What is the value of sum after execution?

Easy
28

A method 'public static void modify(int[][] matrix) { matrix[0][0] = 99; }' is called with 'int[][] values = {{1,2},{3,4}}; modify(values);'. What is the value of values[0][0] after the call?

Hard
29

A programmer writes code to transpose a 2D array (matrix). Given: int[][] matrix = {{1,2},{3,4}}; int[][] result = new int[2][2]; for (int i=0; i<2; i++) for (int j=0; j<2; j++) result[j][i] = matrix[i][j]; What is the value of result[1][0]?

Hard
30

Consider a method that takes an int array and modifies it: public static void doubleArray(int[] arr) { for (int i = 0; i < arr.length; i++) { arr[i] *= 2; } }. What is the output of: int[] nums = {1, 2, 3}; doubleArray(nums); System.out.println(nums[1]);

Medium
31

A developer implements a method to check if a number exists in an array using binary search. The array is not sorted. What will happen?

Hard
32

Refer to the exhibit. What is the output?

Easy
33

Which two statements about the Arrays class are true? (Choose two.)

Medium
34

A banking application stores daily transaction amounts in an array. Which declaration correctly creates an array of 31 double values?

Easy
35

A team is developing a financial application that processes large arrays of market data. They have a method that calculates moving averages by copying a subarray for each window. The current implementation creates a new array for each window using System.arraycopy. The application is running slowly in production. The team identifies that the method is called millions of times per minute. The array is large and the window size is small. The garbage collector overhead is high due to many short-lived arrays. Which optimization should they apply to reduce object creation and improve performance?

Hard
36

A method is designed to compute the average of an array of test scores. What should the method return if the array is empty (length 0)?

Easy
37

Which TWO statements are correct about array declaration and initialization in Java?

Easy
38

In a login system, the authentication method receives an array of user roles as a String[] and checks if a specific role is present. The array may be large (thousands of roles), and the method is called frequently for each user request. Performance is critical. The array is static and does not change after initialization. Which approach is most efficient for repeated checks?

Medium
39

A developer needs to search an unsorted array of 100,000 customer IDs (int) for a specific ID. Which approach is most efficient for a single search?

Hard
40

A method 'public static double average(int[] numbers) { int sum = 0; for (int i = 0; i < numbers.length; i++) sum += numbers[i]; return sum / numbers.length; }' is called with array {10, 20, 30}. What change is needed to return the correct average?

Medium
41

Which THREE statements are correct about the 'main' method signature in Java?

Hard
42

A method is declared as: public static int[] generateSequence(int n) { ... }. Which return statement is valid inside this method?

Hard
43

A developer writes a method that accepts an array and returns the sum of all elements. Which implementation is correct if the array might be null?

Medium
44

A method is designed to reverse an array of integers. The method signature is: public static void reverse(int[] arr). The method correctly reverses the array. Which statement is true about the method?

Easy
45

A new developer writes a method that accepts an array and intends to swap the first and last elements. The code is: public static void swapEnds(int[] arr) { int temp = arr[0]; arr[0] = arr[arr.length-1]; arr[arr.length-1] = temp; } What is a potential issue with this method if the array is empty?

Easy
46

What is the output?

Medium
47

A method is declared as 'public void printElements(int... numbers)'. Which invocation will cause a compilation error?

Easy
48

A developer is writing a method to compute the average of an array of scores. The method should handle edge cases gracefully. The scores array may be empty or contain null values if the collection was interrupted. The scores are stored as primitive doubles. Which implementation is safest and follows best practices?

Easy
49

Refer to the exhibit. Which overloaded methods cause this compilation error?

Medium
50

A team is developing a Java application for an online store. The application has a class 'Inventory' that maintains an array of 'Product' objects. The method 'public void addProduct(Product p)' is intended to add a product to the array. The current implementation uses a fixed-size array of length 100. However, the business has grown, and the array may exceed its capacity. The team needs a solution that allows dynamic resizing without changing the method signature. Which approach should the team take?

Medium
51

A developer writes a method that takes an int array and returns the sum of its elements. The method signature is: 'public static int sumArray(int[] arr)'. Which statement correctly calls this method?

Medium
52

Which TWO statements are true about passing arrays to methods in Java?

Medium
53

Which two statements about method parameter passing in Java are true? (Choose two.)

Hard
54

Which method invocation is ambiguous given these overloaded methods? public void process(int[] a) and public void process(int... a)

Medium
55

What is the output?

Easy
56

A method 'public static int findMax(int[] numbers)' returns the maximum value in the array. Which implementation correctly handles an empty array by returning 0?

Medium
57

Consider the following code: int[] arr = new int[5]; for (int i = 0; i <= arr.length; i++) { arr[i] = i; } System.out.println(arr[0]); What is the result?

Medium
58

Given the method: public static void modify(int[] data) { data = new int[]{10,20}; } What is the output of: int[] vals = {1,2}; modify(vals); System.out.println(vals[0]);

Medium
59

What is printed when the main method runs?

Medium
60

A method that calculates the average of an array of doubles is defined as: public static double average(double[] values) { double sum = 0; for (double v : values) sum += v; return sum / values.length; } Which call is valid?

Easy
61

A developer wants to sort an array of primitive ints in descending order. Which approach will work without using third-party libraries?

Hard
62

What is the result of the following code? int[] arr = new int[3]; arr[3] = 5; System.out.println(arr[3]);

Easy
63

A developer writes a method that takes a variable number of integer arguments and returns the maximum. Which method signature is correct?

Medium
64

Which of the following correctly describes the effect of the method call 'Arrays.sort(myArray)' on an array of objects that do not implement Comparable?

Hard
65

Which two statements about passing arrays to methods are correct? (Select two.)

Hard
66

Given 'int[] source = {1,2,3,4,5};' and 'int[] dest = new int[3];' which code correctly copies the first three elements from source to dest using System.arraycopy?

Hard
67

Which of the following correctly uses the shorthand array initializer to declare and initialize an array of strings with the elements "A", "B", and "C"?

Easy
68

Arrange the steps to create an object from a class in Java in the correct order.

Medium
69

Which THREE statements are true about method overloading in Java?

Hard
70

An application requires storing a fixed set of 12 monthly temperatures. Which initialization is most appropriate?

Medium
71

A company's legacy code has a method that takes an array of integers and returns a new array containing only the positive numbers. The current implementation uses a fixed-size array equal to the input size and counts positive numbers, then copies them, but if many negatives exist, the result array has trailing zeros (which are removed by copying again). This wastes memory and time. The array can be large (up to 1 million elements). The developer wants to improve memory efficiency and runtime without using external libraries. Which approach should they implement?

Hard
72

What is the output of the following code? int[] a = {1,2,3}; int[] b = a; b[0] = 99; System.out.println(a[0]);

Easy
73

A developer is working on a Java program that processes sensor data. The data is stored in a 2D array 'double[][] readings', where each row represents a sensor and each column a time interval. The method 'public static double[] averagePerSensor(double[][] data)' should compute the average reading for each sensor (row) and return a 1D array of averages. The developer writes the following implementation: 'double[] result = new double[data.length]; for (int i = 0; i < data.length; i++) { double sum = 0; for (int j = 0; j < data[i].length; j++) { sum += data[i][j]; } result[i] = sum / data[i].length; } return result;'. However, the program sometimes throws a NullPointerException. What is the most likely cause?

Hard
74

Which three statements about arrays are correct? (Choose three.)

Easy
75

Refer to the exhibit. The code at line 6 of ArrayExample.java is: int[] arr = {10, 20, 30, 40, 50}; int sum = 0; for (int i = 0; i <= arr.length; i++) sum += arr[i]; Which change fixes the exception?

Hard

Frequently asked questions

What does the Arrays and Methods domain cover on the 1Z0-811 exam?
Arrays and Methods questions test whether you can apply the concept in context, not just recognise a definition.
How many questions are in this domain?
This page lists all 75 Arrays and Methods questions in the 1Z0-811 question bank. The actual exam draws from this domain proportionally to its weighting in the official exam blueprint.
What is the best way to practise this domain?
Start with a short focused session (10 questions) to identify gaps, then work through explanations. Repeat with a longer session once the weak areas feel solid.
Can I practise only Arrays and Methods questions?
Yes — the session launcher on this page filters questions to this domain only. Choose any session length for inline explanations and scoring.
Oracle Java Foundations 1Z0-811 Arrays and Methods Practice Questions