Question 8
Back to Exercise
The code below stops with an uncaught error. Which statement correctly describes the problem?
class Vehicle {
constructor(wheels) { this.wheels = wheels; }
}
class Bike extends Vehicle {
constructor(brand) {
this.brand = brand;
super(2);
}
}
console.log(new Bike("Hero").brand);
- A ReferenceError: super() must be called before this is used in a derived constructor Correct
- B It prints Hero
- C TypeError
- D SyntaxError
Correct Answer: Option A
In a derived class the object is created by the parent constructor, so this exists only after super() returns. Swap the two lines.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!