Created
August 9, 2019 22:18
-
-
Save bugarela/c5470416420d36bf516808b9cb9b8179 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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