Scala: Part 4: Classes & Objects | Rasesh Mori
Scala does not have static members but it has singleton objects. A singleton object definition looks similar to class but with the keyword “object”
When a singleton object shares the same name with a class, it is called that class’scompanion object. You must define both the class and its companion object in the same source file. The class is called the companion class of the singleton object. A class
and its companion object can access each other’s private members.
T o run a Scala program, you must supply the name of a standalone singleton
object with a main method that takes one parameter, an Array[String],
and has a result type of Unit.Read full article from Scala: Part 4: Classes & Objects | Rasesh Mori
Scala does not have static members but it has singleton objects. A singleton object definition looks similar to class but with the keyword “object”
and its companion object can access each other’s private members.
Singleton object acts similar to static block in Java and is executed once it is accessed.
A singleton object that does not share the same name with a companion
class is called a standalone object. You can use standalone objects for many
purposes, including collecting related utility methods together.
class is called a standalone object. You can use standalone objects for many
purposes, including collecting related utility methods together.
object with a main method that takes one parameter, an Array[String],
and has a result type of Unit.Read full article from Scala: Part 4: Classes & Objects | Rasesh Mori
No comments:
Post a Comment