Since the version in the constructor creates a new variable that is simply called the same as your member field, and the member field remains unset. This is called variable shading, where a newly created variable hides / hides the member field.
You need to get rid of the type declaration in the constructor so that you refer to the member variable:
public GroceryBill(Employee Clerk) { itemsInGroceryList = new ArrayList<Item>(); }
You can even be explicit and use this :
public GroceryBill(Employee Clerk) { this.itemsInGroceryList = new ArrayList<Item>(); }
nickb
source share