Tutorial by Examples

A Kotlin interface contains declarations of abstract methods, and default method implementations although they cannot store state. interface MyInterface { fun bar() } This interface can now be implemented by a class as follows: class Child : MyInterface { override fun bar() { ...
An interface in Kotlin can have default implementations for functions: interface MyInterface { fun withImplementation() { print("withImplementation() was called") } } Classes implementing such interfaces will be able to use those functions without reimplementing cl...
You can declare properties in interfaces. Since an interface cannot have state you can only declare a property as abstract or by providing default implementation for the accessors. interface MyInterface { val property: Int // abstract val propertyWithImplementation: String g...
When implementing more than one interface that have methods of the same name that include default implementations, it is ambiguous to the compiler which implementation should be used. In the case of a conflict, the developer must override the conflicting method and provide a custom implementation. ...
interface MyInterface { fun funcOne() { //optional body print("Function with default implementation") } } If the method in the interface has its own default implementation, we can use super keyword to access it. super.funcOne()

Page 1 of 1