Question:
If I have:
it generates a null pointer exception. Why?class point { double x,y; } & import point; class test { public static void main(String args[]) { point[] P = new point[10]; P[0].x = 5; P[0].y = 34874; } }
Answer:
Try:
Your array declaration allocates an array large enough to holdonly 10 pointers to points. Space to hold each point must be allocatedseparately.P[0] = new Point(); P[0].x = 5; etc.