0
if a sub class besides those inherited attributes has it's own attribute how should the constructor look like?
public class Dog extends Mammal{ int speed ;<---- this is its own unique attribute public Dog(String aType, String name, int age, int speed) {<---should it look like this?? should it even be included? super(aType, name, age); this speed = speed ; } @Override public String get_name(){ return name ; } public static void main(String[] args) { } }
1 Odpowiedź
+ 3
Hi Lenoname
This looks fine, and you seem to be using super() correctly.
The extra attribute must be included in the subclass constructor parameter list, this is needed so that the speed can be initialized upon instance creation.
Maybe a typo here, there should be a dot after "this"
this.speed = speed;