mirror of
https://github.com/Nezumi-2711/javascript-training.git
synced 2026-09-22 20:01:31 +00:00
26 lines
354 B
JavaScript
26 lines
354 B
JavaScript
// Inheritance
|
|
|
|
class Animal {
|
|
hello() {
|
|
return "I'm not define animal yet!";
|
|
}
|
|
}
|
|
|
|
class Cat extends Animal {
|
|
hello() {
|
|
return super.hello() + " Now, I'm a cat.";
|
|
}
|
|
}
|
|
|
|
class Dog extends Animal {
|
|
hello() {
|
|
return "I'm a dog.";
|
|
}
|
|
}
|
|
|
|
const cat = new Cat();
|
|
console.log(cat.hello());
|
|
|
|
const dog = new Dog();
|
|
console.log(dog.hello());
|