True or False: Both of the following declarations are legal and equivalent: int[] numbers; int numbers[];
Understand the Problem
The question asks whether two different ways of declaring an integer array in Java are both legal and equivalent. This concerns understanding Java syntax for array declarations.
Answer
True
True. Both int[] numbers;
and int numbers[];
are legal and equivalent ways to declare an integer array in Java.
Answer for screen readers
True. Both int[] numbers;
and int numbers[];
are legal and equivalent ways to declare an integer array in Java.
More Information
In Java, when declaring an array, the square brackets can come either after the data type (int[]) or after the variable name (int numbers[]). Both declarations are functionally equivalent.
Tips
It is generally recommended to use the int[] numbers;
style for better readability, as it clearly indicates that the type of the variable numbers
is an integer array.
Sources
- Chapter 10. Arrays - docs.oracle.com
AI-generated content may contain errors. Please verify critical information