Program demonstrate the example of Interface in Kotlin
package com.includehelp
// Declare Interface
interface Organization{
// Abstract Property
val age:Int
// Property with accessor implementations
val name:String
get() = "Trump"
// interface method with implementations
fun printAge(){
println("Age : $age")
}
// abstract method
fun getSalary(salary:Int)
}
// class implements interface
class Manager:Organization{
// override interface abstract property
override val age=32
// Override interface abstracts method
override fun getSalary(salary: Int) {
println("Your Salary : $salary")
}
}
// Main function, Entry Point of Program
fun main(){
// Create instance of class
val organization=Manager()
// Call function
organization.printAge()
// Call function
organization.getSalary(10000)
// Access properties
println("Name : ${organization.name}")
}
Program demonstrate the example of Interface in Kotlin
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer