Language Fundamentals

Q1: 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 { }

A null

B theDogs

C Compilation fails

D An exception is thrown at runtime

ANS:A - null

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.



img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.