WEB Button DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

Kotlin - Interface

Kotlin - Interface is much similar to Java 8 .

Interface might be done by methods for a class that enables you to utilize its portrayed capacity

The watchword "interface" is utilized to characterize an interface in Kotlin as appeared inside the accompanying bit of code.

interface ExampleInterface {
   var myVar: String     // abstract property
   fun absMethod()       // abstract method
   fun sayHello() = "Hello there" // method with default implementation
}

In the following example, we will be implementing the above interface in a class.

Look at the function named “sayHello()”, which is an implemented method.

interface ExampleInterface  {
   var myVar: Int            // abstract property
   fun absMethod():String    // abstract method
   
   fun hello() {
      println("Hello there, Welcome to welookups.Com!")
   }
}
class InterfaceImp : ExampleInterface {
   override var myVar: Int = 25
   override fun absMethod() = "Happy Learning "
}
fun main(args: Array<String>) {
   val obj = InterfaceImp()
   println("My Variable Value is = ${obj.myVar}")
   print("Calling hello(): ")
   obj.hello()
   
   print("Message from the Website-- ")
   println(obj.absMethod())
}

The above piece of code will yield the following output in the browser.

Calling hello(): Hello there, Welcome to welookups.Com!
Message from the Website-- Happy Learning 

In the above example, we have created two sample interfaces A, B and in the class named "multipleInterfaceExample".