Java, “Variable name” cannot be resolved to a variable

If you look at the scope of the variable ‘hoursWorked’ you will see that it is a member of the class (declared as private int)

The two variables you are having trouble with are passed as parameters to the constructor.

The error message is because ‘hours’ is out of scope in the setter.

Leave a Comment