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 ...

Get Pragmatic Scala now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.