Exam JS-Dev-101 Topic 2 Question 80 Discussion
Actual exam question for Salesforce's JS-Dev-101 exam
Question #: 80
Topic #: 2
Question #: 80
Topic #: 2
Refer to the following code block (with corrected template literals using backticks):
01 class Animal {
02 constructor(name) {
03 this.name = name;
04 }
05
06 makeSound() {
07 console.log(`${this.name} is making a sound.`);
08 }
09 }
10
11 class Dog extends Animal {
12 constructor(name) {
13 super(name);
14 this.name = name;
15 }
16 makeSound() {
17 console.log(`${this.name} is barking.`);
18 }
19 }
20
21 let myDog = new Dog('Puppy');
22 myDog.makeSound();
What is the console output?
01 class Animal {
02 constructor(name) {
03 this.name = name;
04 }
05
06 makeSound() {
07 console.log(`${this.name} is making a sound.`);
08 }
09 }
10
11 class Dog extends Animal {
12 constructor(name) {
13 super(name);
14 this.name = name;
15 }
16 makeSound() {
17 console.log(`${this.name} is barking.`);
18 }
19 }
20
21 let myDog = new Dog('Puppy');
22 myDog.makeSound();
What is the console output?
Suggested Answer: C Vote an answer
Animal class:
Has a constructor that sets this.name.
Has a makeSound method that logs a message using this.name.
Dog class:
Extends Animal.
Its constructor calls super(name) to run the parent constructor, which sets this.name.
It overrides makeSound() to log:
console.log(`${this.name} is barking.`);
Instantiation:
let myDog = new Dog('Puppy');
myDog.makeSound();
new Dog('Puppy'):
Calls Dog constructor with name = 'Puppy'.
Inside, super(name) sets this.name = 'Puppy' in the Animal constructor.
Then this.name = name; in the Dog constructor keeps it as 'Puppy'.
myDog.makeSound():
Calls the overridden makeSound() in Dog.
Logs: "Puppy is barking."
No reference errors, no undefined; the output is:
Puppy is barking.
Study Guide Concepts:
ES6 classes and inheritance (extends)
super() in subclass constructors
Method overriding in subclasses
Template literals: `${this.name} ...`
Has a constructor that sets this.name.
Has a makeSound method that logs a message using this.name.
Dog class:
Extends Animal.
Its constructor calls super(name) to run the parent constructor, which sets this.name.
It overrides makeSound() to log:
console.log(`${this.name} is barking.`);
Instantiation:
let myDog = new Dog('Puppy');
myDog.makeSound();
new Dog('Puppy'):
Calls Dog constructor with name = 'Puppy'.
Inside, super(name) sets this.name = 'Puppy' in the Animal constructor.
Then this.name = name; in the Dog constructor keeps it as 'Puppy'.
myDog.makeSound():
Calls the overridden makeSound() in Dog.
Logs: "Puppy is barking."
No reference errors, no undefined; the output is:
Puppy is barking.
Study Guide Concepts:
ES6 classes and inheritance (extends)
super() in subclass constructors
Method overriding in subclasses
Template literals: `${this.name} ...`
by Warner at Jul 11, 2026, 12:35 AM
0
0
0
10
Comments
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
Report Comment
Commenting
You can sign-up / login (it's free).