Interviews2 answers
What are companion objects in Scala?
2 Answers
Scala classes cannot have static variables or methods. Instead a Scala class can have what is called a singleton object, or sometime a companion object.
A singleton object is declared using the object keyword
Laxmidhar SahooPosted May 7, 2019, 8:28 PM EDT
If a singleton object and class have same name then it is known as a Companion object. Campanion object and class should be defined in the same source file .
Akshay DeshmukhPosted Jan 25, 2019, 4:05 AM EST


