Hi All,
public class Java_arrays{
public static void main(
String[] args) {
Dog[][] theDogs=new Dog[3][];
System.out.println(theDogs[1][0].toString());
}
}
class Dog{
}
This code will give RunTimeError because theDogs[1][0] is having null value.I got that.
I tried to execute the above program with some value.Can anyone help me to figure out where I am doing mistake on the below program.
public class Java_arrays{
public static void main(String[] args) {
Dog[][] theDogs=new Dog[3][];
theDogs[0]=new Dog[2]; //assigning column
Dog theD=new Dog(5);
theDogs[0][1] =theD.p;
System.out.println(theDogs[1][0].toString());
}
}
class Dog{
int p;
Dog(int p){
this.p=p;
}
}
I would like to get the answer 5.Please help me.