WEB Button DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

Kotlin - Class & Object

We will learn about class and its object . By definition of OOP, a class is a blueprint of a runtime entity and object is its state. which includes both its behavior and state.
Class myClass { // class Header 

   // class Body
}
its object through which we will access different data members of that class.
class myClass {
   // property (data member)
   private var name: String = "Welookups.com"
   
   // member function
   fun printMe() {
      print("You are at the best Learning website Named-"+name)
   }
}
fun main(args: Array<String>) {
   val obj = myClass() // create obj object of myClass class
   obj.printMe()
}
code will yield the following output in the browser
You are at the best Learning website Named- Welookups.com

Nested Class

In Kotlin Programming nested class is by default statichence, it can be accessed without creating any object of that class.
fun main(args: Array<String>) {
   val demo = Outer.Nested().foo() // calling nested class method
   print(demo)
}
class Outer {
   class Nested {
      fun foo() = "Welcome to The Welookups.com"
   }
}
code will yield the following output in the browser.
Welcome to The Welookups.com

Inner Class

When a nested class is marked as a “inner”, then it will be called as an Inner class.
fun main(args: Array<String>) {
   val demo = Outer().Nested().foo() // calling nested class method
   print(demo)
}
class Outer {
   private val welcomeMessage: String = "Welcome to the Welookups.com"
   inner class Nested {
      fun foo() = welcomeMessage
   }
}
code will yield the following output
Welcome to the Welookups.com

Anonymous Inner Class

Anonymous inner class is a very important point that makes the life of a programmer very easy.we will create an object of that interface using Anonymous Inner class mechanism.
fun main(args: Array<String>) {
   var programmer :Human = object:Human // creating an instance of the interface {
      override fun think() { // overriding the think method
         print("I am an example of Anonymous Inner Class ")
      }
   }
   programmer.think()
}
interface Human {
   fun think()
}

code will yield the following output in the browser.

I am an example of Anonymous Inner Class 

Type Aliases

Type aliases are a property of Kotlin compiler. It provides the flexibility of creating a new name of an existing type

typealias NodeSet = Set<Network.Node>
typealias FileTable<K> = MutableMap<K, MutableList<File>>