All quizzesMedium
Inheritance & Prototypes
Preview — 3 of 10 questions
What does the super keyword do in a subclass?
javascript
class Parent {
constructor(name) {
this.name = name;
}
}
class Child extends Parent {
constructor(name, age) {
super(name);
this.age = age;
}
}ACalls the parent class constructor
BCreates a new instance of the parent class
CRefers to the child class instance
DOverrides the parent class constructor
What happens when a subclass defines a method with the same name as a method in its parent class?
javascript
class Animal {
speak() {
return "Some sound";
}
}
class Dog extends Animal {
speak() {
return "Woof";
}
}
const dog = new Dog();
console.log(dog.speak()); // "Woof"AJavaScript throws an error
BThe parent method is deleted
CThe subclass method overrides the parent method
DBoth methods are merged
Which statement about static methods is true?
javascript
class Example {
static sayHello() {
return "Hello!";
}
}AExample.sayHello() will work
Bnew Example().sayHello() will work
CStatic methods can access instance properties
DStatic methods are inherited automatically
Sign up free to play
Answer all 10 questions (7 more), see explanations for every answer, and track your score.