<p>Open developer console to see output</p>
class Animal {
constructor(noise) {
this.noise = noise;
}
eat() {
console.log("Om nom nom");
}
sleep() {
console.log("Zzzzzzz");
}
makeNoise() {
console.log(this.noise);
}
}
class Pig extends Animal {
constructor() {
super("Oink!");
}
wallowInMud() {
console.log("Aaaahh...");
}
}
class Horse extends Animal {
constructor() {
super("Neigh!");
}
prance() {
console.log("Eeek!!");
}
}
class Human extends Animal {
constructor() {
super("Cogito ergo sum.");
}
inventFire() {
console.log("Ow, that's hot!");
}
}
class Bird extends Animal {
constructor(noise, canFly = true) {
super(noise);
this.canFly = canFly;
}
fly() {
if (this.canFly) {
console.log("I'm flyyyying");
} else {
console.log("I can't fly, you fools!");
}
}
layEgg() {
console.log("*Plop*");
}
}
class Owl extends Bird {
constructor() {
super("Hoot");
}
}
class Kiwi extends Bird {
constructor() {
super("Shriek!", false);
}
}
const pig = new Pig();
const horse = new Horse();
const human = new Human();
const owl = new Owl();
const kiwi = new Kiwi();
pig.makeNoise();
pig.wallowInMud();
horse.makeNoise();
horse.prance();
human.makeNoise();
human.inventFire();
owl.makeNoise();
owl.layEgg();
owl.fly();
kiwi.makeNoise();
kiwi.layEgg();
kiwi.fly();
console.log(pig, horse, human);
console.log(owl, kiwi);
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.