Interface is declared by
● using Keyword interface interface
● followed by Interface Name InterfaceA
● followed by Interface Body which can have
Methods abstract void abstractMethod() (abstract, static, default)
Properties abstract void abstractMethod() (abstract, static, default)
Syntax
interface InterfaceA { }
interface InterfaceB { }
class Person : InterfaceA, InterfaceB { }
Syntax
//===========================================================================================================
//INTERFACE: InterfaceA
//===========================================================================================================
interface InterfaceA {
abstract fun abstractMethod();
}
//===========================================================================================================
//INTERFACE: InterfaceB
//===========================================================================================================
interface InterfaceB {
fun defaultMethod1() { println("defaultMethod1()"); }
fun defaultMethod2() { println("defaultMethod2()"); }
}
//===========================================================================================================
//CLASS: Person
//===========================================================================================================
class Person : InterfaceA, InterfaceB {
override fun abstractMethod() { println("Overriden abstractMethod()" ); }
override fun defaultMethod1() { println("Overriden defaultMethod1()" ); }
constructor() {
}
}
//===========================================================================================================
//FUNCTION: main
//===========================================================================================================
fun main() {
//CREATE INSTANCE.
var john : Person = Person()
john.abstractMethod()
john.defaultMethod1() //Call overriden Method
john.defaultMethod2() //Call Parent's Method
}