You have at least two problems. First, you can create a new variable with the same name as another variable that's in a bigger container (scope). In this case, the new variable "hides" or "shadows" the outer one. In your setInv
method, when you say inv = inv
, both inv
s refer to the innermost variable, the one in the method signature. To save the argument to the class's field, you need to specify the outer inv
: this.inv = inv;
.
In your CreatePurchase
class, you don't have any inv
defined; there's one in Purchase
, but that's over there, not here. You just need to declare int inv;
right after your Purchase one
.
Based on these two errors, I would recommend reading an article or tutorial about variable scope in Java to learn the rules about which variables are accessible where.