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
Your Answer
Choose the Best Option
Click any option to instantly check if you're correct.
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.
Continue Practice
Share
Share This Question
Challenge a friend or share with your study group.
More from This Topic