This is because of variable shadowing in the overloaded constructor of Check2.
The assignments in that constructor assign the parameters to themselves, instead of to the instance variables, as you intended.
This will become apparent when you declare the constructor parameters as final, like so:
It will not, however fix the problem. How do you think you could or should fix this?
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Jelle Klap wrote:This is because of variable shadowing in the overloaded constructor of Check2.
The assignments in that constructor assign the parameters to themselves, instead of to the instance variables, as you intended.
This will become apparent when you declare the constructor parameters as final, like so:
It will not, however fix the problem. How do you think you could or should fix this?
Jelle Klap wrote:Sure, that's definitely one way to go.
Another would be to make use of the this keyword, which let you keep the identical names and prevent shadowing: