Scala – Singleton Object

In this tutorial, we are going to learn what is Singleton Object in Scala. You would be aware of static keyword in java which belongs to the class. One way in which Scala is more object-oriented than Java is that classes in Scala cannot have static members. Instead, scala uses Singleton Object. Singleton object is defined similar to class definition, except that we use Object keyword instead of Class keyword.

The methods, variable declared inside scala singleton object are globally accessible. We don’t need to create an object from class. We can directly call methods declared inside singleton object.

Because the method model is defined in an object instead of a class, it can be called in the same way as a static method in Java. A singleton object can extend classes and traits.

Scala - Objects & Classes
Scala - Companion Object
Shekhar Sharma

Shekhar Sharma

Shekhar Sharma is founder of He is an automation engineer having more than 8 years of experience who loves troubleshooting in automation and finding innovative ways to solve the problems. His other leisurely activities includes playing harmonica, paintings, sketching portrait, watching movies and travelling etc.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *