Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Kotlin Object

Devrath edited this page Aug 24, 2022 · 1 revision
  • In Java if we want to access the member field and member function of a class we use the static keyword.
  • The static keyword represents the singleton pattern. And by the singleton pattern, we are able to have one instance of a class.
  • We create singleton so that we can share the same instance and resources throughout and sometimes the reason can be because these resources are expensive to create.
  • Can the object class be inherited? --> No, Instead we need to enclose it in an open class and then need to get access to the items of it
  • Can we have a constructor in the object class? --> No, Instead we can have a init{} method and initialize anything if needed
Object Singleton {
      var count : Int = 0;
      fun appendCount(){
            count++
      }
}

Clone this wiki locally

Morty Proxy This is a proxified and sanitized view of the page, visit original site.