Skip to content

Instantly share code, notes, and snippets.

@bugarela
Created August 9, 2019 22:18
Show Gist options
  • Save bugarela/c5470416420d36bf516808b9cb9b8179 to your computer and use it in GitHub Desktop.
Save bugarela/c5470416420d36bf516808b9cb9b8179 to your computer and use it in GitHub Desktop.
open class Shape{
class Circle(val radius: Float) : Shape()
class Rect(val base: Float, val height: Float) : Shape()
fun area() : Float{
return when(this){
is Shape.Circle -> 2.0f * 3.14f * this.radius
is Shape.Rect -> this.base * this.height
else -> 0.0f
}
}
}
fun main()=print(Shape.Circle(2.0f).area())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment