An interface is somewhat similar to an abstract class in that it provides a list of functions to implement. An interface is basically a contract between classes in which each class has to provide an implementation of the functions that are defined in the interface. An interface is declared with the interface keyword. Let's take a look at an example:
interface interface_name{
fun func1()
fun func2()
}
interface IPrintable {
fun print()
}
Creating an interface is similar to creating a class. The names of the interfaces start with the letter I. This is not a syntax requirement, but a common practice to differentiate between classes and interfaces because their syntax is similar:
class Invoice : IPrintable {
override fun print() {
println("Invoice is printed")
}
}
In this example, the Invoice class implements the IPrintable interface...