Correct Answer: A
FishingBoat extends Ship, so it is a subclass. In ES6 classes:
When you define a constructor in a subclass, you must call super(...) before accessing this.
super(size) calls the parent class (Ship) constructor, which sets this.size = size.
So the correct constructor is:
class FishingBoat extends Ship {
constructor(size, capacity) {
super(size); // line 09
this.capacity = capacity;
}
displayCapacity() {
console.log(`The boat has a capacity of ${this.capacity} people.`);
}
}
Why others are incorrect:
B . ship.size = size;
ship is not defined; this would cause a ReferenceError.
C . super.size = size;
super is not an instance; you must call super(...) as a function to invoke the parent constructor.
D . this.size = size;
In a subclass constructor, you must call super() before using this, otherwise you get a ReferenceError. Also this bypasses the parent constructor logic.
Relevant concepts: ES6 class inheritance, extends, super() in subclass constructors, this initialization rules.