I am practicing techniques learned by writing a small battle simulator. In my hero class I have methods for storing damage. The methods are:
private strike;
public void setStrike(int attack){
attack = strike;
}
public int retStrike(){
return strike;
}
In my main method, I have a call for a new Random number.
int randomNum = new Random().nextInt(10)+1;
Mike.setStrike(randomNum);
When I call the object Mike and feed the setStrike method in the Hero class’s setStrike method, it always returns 0. What am I doing wrong? Thanks!
This should be: –
You used your assignment opposite. The first assignment has no effect on the private field
strike.