I tried executing the following code
public class Phonebook {
String name;
long phno;
}
public class Store {
public static void main(String args[]) {
Phonebook p[] = new Phonebook[10];
p[0].name = "vasvi";
p[0].phno = 123456;
p[1].name = "abcd";
p[2].phno = 903747;
System.out.println(p[0].name + " " + p[1].name);
}
}
This code when executed gives the NullPointerException
. I don't seem to understand why. I have learnt that classes are user defined data types. So I'm really confused why such an exception would arise?