InterviewSolution
Saved Bookmarks
| 1. |
Does Scala support static methods? If not, then how can we write object-independent or class level methods in Scala? |
|
Answer» Scala doesn’t have a static keyword to DEFINE the OBJECT-independent METHODS. We can directly define them in a singleton object. Otherwise, we can use a companion object for a given class for holding those methods. For example, we can create a List in Scala in the following way, val l = List(1, 2, 3, 4)This is POSSIBLE as there is a method named apply defined in the object - List . |
|