interface IAnimal {
eat() : void;
}
class Dog implements IAnimal {
eat() : void {
console.log("Dog eats");
}
}
class Cat implements IAnimal {
eat() : void {
console.log("Cat eats");
}
}
class Owner {
feed(animal: IAnimal) : void {
animal.eat();
}
}
// driver code below
const dog = new Dog();
const cat = new Cat();
dog.eat();
cat.eat();
const owner = new Owner();
owner.feed(dog);
owner.feed(cat);
To embed this project on your website, copy the following code and paste it into your website's HTML: