In this example, we will create an ICardLimit interface which defines the card limits of various card types and we create enum CardType class which implements ICardLimit interface.
Enums Implementing Interfaces
package net.javaguides.kotlin.examples
interface ICardLimit {
fun getCreditLimit(): Int
}
enum class CardType: ICardLimit {
SILVER {
override fun getCreditLimit() = 100000
},
GOLD {
override fun getCreditLimit() = 200000
},
PLATINUM {
override fun getCreditLimit() = 300000
}
}
fun main(args: Array < String > ) {
val creditLimit = CardType.PLATINUM.getCreditLimit()
println(creditLimit);
}
Output:
300000
Comments
Post a Comment