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) { } }

21st Sep 2022, 10:37 PM
Lenoname
1 Réponse
+ 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;
22nd Sep 2022, 4:05 AM
Tibor Santa
Tibor Santa - avatar