Complete the code to define a class named Animal.
class [1] { constructor(name) { this.name = name; } }
The class name should be Animal as it represents the base class.
Complete the code to make Dog inherit from Animal.
class Dog [1] Animal { constructor(name, breed) { super(name); this.breed = breed; } }
In JavaScript, extends is used to inherit from another class.
Fix the error in the method overriding speak in Dog class.
class Dog extends Animal { speak() { return [1] + ' barks.'; } }
Use this.name to access the instance's name property inside the method.
Fill both blanks to create a subclass Cat that calls the parent constructor correctly.
class Cat [1] Animal { constructor([2]) { super(name); } }
The class should extend Animal and the constructor should take name as parameter to pass to super.
Fill all three blanks to override the speak method in Cat class and call the parent speak method.
class Cat extends Animal { speak() { return super.[1]() + ' and meows.'; } [2]() { return this.name; } constructor([3]) { super(name); } }
The method speak calls super.speak(). The class defines a getName method returning this.name. The constructor takes name as parameter.