Chapter 4Working with Objects
Scala is fully object-oriented and provides concise syntax for creating classes and working with objects. You can achieve everything that’s possible in Java, and in addition, Scala provides some more powerful features to help with OO programming. Also, even though Scala is a pure object-oriented language, it still has to support Java’s not-so-pure OO concepts like static methods. Scala tackles that in a fairly interesting way using companion objects. Companion objects are singletons that accompany a class and are quite common in Scala.
We’re going to start on familiar ground and quickly dive into the OO aspects of Scala. We’ll port a simple Java class to Scala, and then we’ll dig into Scala’s capabilities. Constructors ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access