I would like to create an instance of a class, that has an array of class members within it where the array is defined in length upon initialization. The code I have written does not contain any errors precompile, but after running returns nullPointerException. I want to be able to access products of class storeA by typing storeA.products[productnumber].(product variable), is this possible?
package tinc2;
public class FirstProgram {
public static void main(String[] args) {
store storeA = new store();
storeA.name = "Walmart";
storeA.products = new store.product[3];
storeA.products[0].name = "Horses";
System.out.println(storeA.products[0].name);
}
public static class store{
String name;
product products[];
static class product{
String name;
int quantity;
double price;
}
}
}