Anonymous
inner classes can be created using object expressions.
Ex
printMessage(object : PrinterUtil() {
override fun welcomeMessage() {
println("Good
Morning customer")
}
})
Find
the below working application.
HelloWorld.kt
open class PrinterUtil { open fun welcomeMessage() { println("Welcome user") } } fun printMessage(printUtl: PrinterUtil) { printUtl.welcomeMessage() } fun main(args: Array<String>) { printMessage(object : PrinterUtil() { override fun welcomeMessage() { println("Good Morning customer") } }) }
Output
Good Morning customer
No comments:
Post a Comment