Created
May 29, 2023 08:14
-
-
Save s1monw1/85be7753c4487b1524bcd007d7b10a03 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
sealed class Mammal(val name: String) | |
class Cat(val catName: String) : Mammal(catName) | |
class Human(val humanName: String, val job: String) : Mammal(humanName) | |
fun greetMammal(mammal: Mammal): String { | |
return when (mammal) { | |
is Human -> "Hello ${mammal.name}; You're working as a ${mammal.job}" | |
is Cat -> "Hello ${mammal.name}" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment