Write 3 classes named Animal
, Dog
and GoldenRetriever
that inherit from each other.
Animal
should
name
in it's constructor and store it in a private propertyname
getter that will return the name of the animalsleep
method that will return {name} is sleeping...
eat
method that will return {name} is eating. Nom nom!
Dog
should inherit from Animal
and
breed
which will be stored in a private propertybreed
getter that will return the breed of the dogbark
method that will return {name}: Woof! Woof!
GoldenRetriever
should inherit from Dog
and
"Golden Retriever"
guardHouse
method that returns: {name} is a Golden Retriever thus too friendly to guard the house.
const myCat = new Animal("Susie");
console.log(myCat.name); // Susie
console.log(myCat.sleep()); // "Susie is sleeping..."
console.log(myCat.eat()); // "Susie is eating. Nom nom!"
const dog = new Dog("Pixel", "German Shepherd");
console.log(dog.name); // Pixel
console.log(dog.sleep()); // "Pixel is sleeping..."
console.log(dog.eat()); // "Pixel is eating. Nom nom!"
console.log(dog.bark()); // "Pixel: Woof! Woof!"
const goldenBoy = new GoldenRetriever("Goldie");
console.log(goldenBoy.name); // Goldie
console.log(goldenBoy.sleep()); // "Goldie is sleeping..."
console.log(goldenBoy.eat()); // "Goldie is eating. Nom nom!"
console.log(goldenBoy.bark()); // "Goldie: Woof! Woof!"
console.log(goldenBoy.guardHouse()); // "Goldie is a Golden Retriever thus too friendly to guard the house."