Java OCA OCP Practice Question 857

Question

What is the output of the following?

public class Main {
   public static void main(String[] args) {
      String[][] listing = new String[][] { { "A" }, { "B", "29.99" } };
      System.out.println(listing.length + " " + listing[0].length);

   }
}
  • A. 2 1
  • B. 2 2
  • C. The code does not compile.
  • D. The code compiles but throws an exception at runtime.


A.

Note

This array has two elements, making listing.length output 2.

While each array element does not have the same size, this does not matter because we are only looking at the first element.

The first element has one.

This makes the answer Option A.




PreviousNext

Related