Skip to content

Instantly share code, notes, and snippets.

@Mahdhir
Created January 31, 2021 16:36
Show Gist options
  • Save Mahdhir/6775be1d9516b7cff5194f88bfce6a14 to your computer and use it in GitHub Desktop.
Save Mahdhir/6775be1d9516b7cff5194f88bfce6a14 to your computer and use it in GitHub Desktop.
interface IDuck{
walk():void;
quack():void;
}
class Duck implements IDuck{
walk():void {
console.log("Duck walk");
}
quack():void {
console.log("Duck quack");
}
toString():String{
return "I am a duck who walks and quacks";
}
}
interface IPelican{
walk():void;
quack():void;
dive():void;
}
class Pelican implements IPelican{
walk():void {
console.log("Pelican walk");
}
quack():void {
console.log("Pelican quack");
}
dive():void {
console.log("Pelican dive");
}
toString():String{
return "I am a pelican who walks, quacks and dives";
}
}
class Platypus {
walk():void {
console.log("Platypus walk");
}
growl():void {
console.log("Platypus growl");
}
toString():String{
return "I am a platypus who walks and growls";
}
}
function print(duck:IDuck){
console.log("Input is a duck\n" + duck.toString());
}
let duck = new Duck();
let pelican = new Pelican();
let platypus = new Platypus();
print(duck);
print(pelican);
print(platypus);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment