Java Programming - Language Fundamentals - Discussion
Discussion Forum : Language Fundamentals - Finding the output (Q.No. 4)
4.
What 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 { }
Answer: Option
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.
Discussion:
14 comments Page 2 of 2.
Sid said:
9 years ago
Why not compilation fails?
Raj said:
8 years ago
Why array didn't initialized automatically?
Shr said:
8 years ago
But Dog is a class. And if we want to create an array fo object we need only one subcript.
Devi said:
6 years ago
Dog is a class and why the object has been created like that?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers