Created
December 14, 2017 04:50
-
-
Save ktutnik/e1b731114787ad890949d6b8a9d4bf85 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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