Created
June 12, 2023 11:18
-
-
Save kalaiselvan369/75a0d383adde93e8deba31a6988f9bf7 to your computer and use it in GitHub Desktop.
Operator Overloading
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
import java.sql.Date | |
fun main() { | |
exploreRangeTo() | |
val scoreBoard = ScoreBoard() | |
scoreBoard + 6 | |
println(scoreBoard.displayScore()) | |
} | |
// operator overloading based on kotlin library function | |
fun exploreRangeTo() { | |
val startDate = Date.valueOf("2023-06-12") | |
val endDate = Date.valueOf("2023-06-15") | |
val range = startDate..endDate | |
println(range) | |
val isDatePresent = Date.valueOf("2023-06-13") in range | |
println(isDatePresent) | |
} | |
class ScoreBoard { | |
private var score: Int = 0 | |
operator fun plus(run: Int) { | |
this.score += run | |
} | |
fun displayScore() { | |
println(score) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment