Single Choice Not Set

QWhat will be the output of the program?
public class TestDogs 
{
    public static void main(String [] args) 
    {
        Dog [][] theDogs = new Dog[3][];
        System.out.println(theDogs[2][0].toString());
    }
}
class Dog { }

ID: #1997 Java Language Fundamental 2,334 views
Question Info
#1997Q ID
Not SetDifficulty
Java Language FundamentalTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A null
  • B theDogs
  • C Compilation fails
  • D An exception is thrown at runtime
Correct Answer

Explanation

The second dimension of the array referenced by theDogs has not been initialized. Attempting to access an uninitialized object element (System.out.println(theDogs[2][0].toString());) raises a NullPointerException.

Share This Question

Challenge a friend or share with your study group.