So i have a parent class Warrior and a Knight class that extends Warrior. Instructions in tasks says Warrior has 2 fields:
- int health = 50,
- int attack = 5
Knight must have attack amount of 7. How to properly change Knight "attack" field without breaking SOLID rules etc. My code looks like that rn.
public class Warrior {
private int health;
private int attack;
public Warrior() {
this.health = 50;
this.attack = 5;
}
public void setAttack(int attack) {
this.attack = attack;
}
-----------------------------------------------
public class Knight extends Warrior {
public Knight() {
super.setAttack(7);
}
}
And it works just as i want but i think there is a better solution that i cannot find. Can i just change modificator of attack field on public and then go for super.attack?