Skip to content

Instantly share code, notes, and snippets.

@ktutnik
Created December 14, 2017 04:50
Show Gist options
  • Save ktutnik/e1b731114787ad890949d6b8a9d4bf85 to your computer and use it in GitHub Desktop.
Save ktutnik/e1b731114787ad890949d6b8a9d4bf85 to your computer and use it in GitHub Desktop.
versi C#
class Animal {
speak(){}
}
class Bird : Animal {
fly(){}
}
class Dog : Animal {
bark() {}
}
var animal //instance bisa Bird atau Dog
var dog = animal as Dog
if(dog != null) dog.bark()
var bird = animal as Bird
if(bird != null) bird.fly()
-------------------
yen di type script
if(animal instanceof Bird) animal.fly()
if(animal instanceof Dog) animal.bark()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment