Which of the following code snippets declares a jagged array?
- int jaggedArray[3][];
- int[3][] jaggedArray;
- int[] jaggedArray[3];
- int[][] jaggedArray = new int[3][];
A jagged array is an array of arrays in which the sub-arrays can have different lengths. The correct declaration for a jagged array in Java is option 1, where you specify the number of rows (3) but leave the size of the second dimension unspecified. This allows each sub-array to have a different length.
Loading...
Related Quiz
- The ________ keyword is used to provide the default implementation of a method declared in an interface.
- The Character class in Java is used to wrap a value of the primitive data type ________.
- Which searching algorithm requires the data to be sorted to work effectively?
- How can you customize the serialization process to handle custom object serialization?
- When a thread acquires a lock for a synchronized method, what happens to the other threads that are trying to access it?