JavaScript
class Animal {
constructor(name) { this.name = name; }
speak() { return this.name + ' makes a sound'; }
}
class Dog extends Animal {
speak() { return this.name + ' barks'; }
}Output
// Inheritance example
Inheritance enables code reuse through classes.