Kotlin - Interface

Kotlin - Interface is much like Java 8 .

nterface may be carried out by means of a class that allows you to use its described capability

The keyword "interface" is used to define an interface in Kotlin as shown inside the following piece of code.

interface ExampleInterface 
   var myVar: String     // abstract property
   a laugh absMethod()       // summary approach
   a laugh sayHello() = "Hello World!" // method with default implementation

Look at the characteristic named "sayHello()", which is an implemented technique.

In the following example, we are able to be implementing the above interface in a class.

interface ExampleInterface  
   var myVar: Int            // summary property
   amusing absMethod():String    // abstract technique
   amusing hello() 
      println("Hello there, Welcome to Welookups.Com!")

magnificence InterfaceImp : ExampleInterface 
   override var myVar: Int = 25
   override a laugh absMethod() = "Start Learning "

fun essential(args: Array) 
   val obj = InterfaceImp()
   println("My Variable Value is = $obj.MyVar")
   print("Calling hi there(): ")
   obj.Hi there()
   print("Message from the Website-- ")

Calling whats up(): Hello there, Welcome to Welookups.Com!
Message from the Website-- Start Learning 

Kotlin doesn’t assist a couple of inheritances

In the following example, we can create two interfaces and later we can put into effect both the interfaces into a clas

interface A 
   fun printMe() 
      println(" method of interface A")

interface B  
   amusing printMeToo() 
      println("I am any other Method from interface B")

// implements two interfaces A and B
class multipleInterfaceExample: A, B

a laugh foremost(args: Array) 
   val obj = multipleInterfaceExample()

In the above instance, we've created pattern interfaces A, B and in the elegance named "multipleInterfaceExample"

method of interface A
I am another Method from interface B