What is the issue, if any, with the following statement: int[][] arr = new int[][5];?
- It declares a 2D array with a missing size for the first dimension.
- It declares a 2D array with a missing size for the second dimension.
- It declares a 2D array with a size of 5 for both dimensions.
- It declares a valid 2D array in Java.
The statement is incorrect because when declaring a 2D array, you need to specify the size of both dimensions. In this case, the size for the second dimension is missing (int[][5]). The correct syntax would be something like int[][] arr = new int[3][5];, where 3 is the number of rows, and 5 is the number of columns.
Loading...
Related Quiz
- Consider a scenario where you want to invert the sign of a numeric value only if a particular boolean condition is true. How can unary operators be utilized to achieve this without using an if statement?
- What happens if no constructor is provided in a Java class?
- Which block among try, catch, and finally is optional in exception handling?
- ________ is an interface in JDBC, which can be used to move a cursor in the result set in both directions.
- Which class is used to create a server-side socket that waits for client requests?