Which of the following statements correctly initializes a two-dimensional array in Java?
- int[][] arr = new int[3][3];
- int[][] arr = {{1,2,3}, {4,5,6}, {7,8,9}};
- int[][] arr = new int[2][];
- int[][] arr = new int[][3];
In Java, a two-dimensional array can be initialized using the curly braces {} with values enclosed in them. Option 2 correctly initializes a 2D array with values, while the other options are incorrect or incomplete.
Loading...
Related Quiz
- In a real-world application managing user profiles, how might parameterized constructors be used to quickly initialize user objects with provided details during registration?
- Which of the following is a valid method to execute a stored procedure using JDBC?
- Can an interface contain static methods in Java?
- A ________ is a result-bearing computation that can be canceled and can compute the result asynchronously provided by ExecutorService.
- The class ________ allows an application to write primitive Java data types to an output stream in a portable way.