Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Class Inheritance

Object-Oriented Programmingmedium

Course · Section 14: Object-Oriented Programming (OOP) With JavaScript · Lecture 233: Inheritance Between "Classes": ES6 Classes

Using an `Animal` base class and a `Dog` subclass that extends it, implement `dogSound(name)` returning the name followed by ` barks`.

Sample tests

Input: dogSound("Rex")
Output: "Rex barks"
Input: dogSound("Bud")
Output: "Bud barks"

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • A subclass constructor that does not call super() throws.
Visualize this concept: Prototypes and Inheritance →
Approach & explanation (try first)

Dog inherits name from Animal and adds a speak method, demonstrating class inheritance.

Loading...
⌘/Ctrl + Enter

Run your code to see results.