Created
June 21, 2019 11:31
-
-
Save sidd-kulk/e196d13fbf6d1e814db8c93d40e8f653 to your computer and use it in GitHub Desktop.
Kotlin code sample
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
fun main() { | |
val s = Square(2.0) | |
println(s.area()) // Prints 4.0, duh! | |
println(s - Square(3.0)) // Prints -5.0, Sweet! | |
} | |
data class Square (val side: Double) { | |
operator fun minus(other: Square): Double { | |
return this.area() - other.area() | |
} | |
fun area(): Double { | |
return side * side | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment