JSFiddle - React, Tailwind, and code Playground
by KARTHIKEYAN K
JavaScript
class Animal
{
name:string
constructor(_name: string)
{
this.name = _name;
}
move(distanceInMeter: number)
{
console.log(`${this.name} moved ${distanceInMeter}m.`);
}
makeSound(soundName:string)
{
console.log(`${soundName}.....`);
}
}
class cat extends Animal
{
constructor(name: string)
{
super(name);
}
move(distanceInMeter: number)
{
super.move(distanceInMeter);
}
makeSound(soundName: string)
{
super.makeSound(soundName);
}
}
class duck extends Animal
{
constructor(name: string)
{
super(name);
}
move(distanceInMeter: number)
{
super.move(distanceInMeter);
}
makeSound(soundName: string)
{
super.makeSound(soundName);
}
}
var _cat = new cat('Tom');
_cat.move(20);
_cat.makeSound('Meow Meow Meow');
var _animal: Animal;
_animal = new duck('Baby fluff');
_animal.move(30);
_animal.makeSound('Quack');