Skip to main content
4 of 12
deleted 101 characters in body
erluxman
  • 19.6k
  • 22
  • 101
  • 129

1. Define : Any method/ val/ var inside object( keyword for Singleton) will act like static in java . If you want that object inside any class use companion, else its optional.

Remember the trick is : object i.e. singleton

object Foo{ fun sayFoo() = println("Foo") val bar ="bar" } 

2.Usage :

Foo.sayFoo() println(Foo.bar) 

3.Output :

Foo bar 
erluxman
  • 19.6k
  • 22
  • 101
  • 129