JavaScript Classes
<!DOCTYPE html> <html> <body> <h2>Class Inheritance</h2> <script> class Animal { constructor(name) { this.name = name; } speak() { return this.name + " makes a sound."; } } class Dog extends Animal { speak() { return this.name + " barks."; } } const rex = new Dog("Rex"); console.log(rex.speak()); // "Rex barks." console.log(rex.name); // "Rex" (inherited) </script> </body> </html>