You are previewing Scala for the Impatient.

Scala for the Impatient

Cover of Scala for the Impatient by Cay S. Horstmann Published by Addison-Wesley Professional
O'Reilly logo

Chapter 6. Objects

Topics in This Chapter image

6.1 Singletons — page 65

6.2 Companion Objects — page 66

6.3 Objects Extending a Class or Trait — page 67

6.4 The apply Method — page 67

6.5 Application Objects — page 68

6.6 Enumerations — page 69

Exercises — page 71

In this short chapter, you will learn when to use the object construct in Scala. Use it when you need a class with a single instance, or when you want to find a home for miscellaneous values or functions.

The key points of this chapter are:

• Use objects for singletons and utility methods.

• A class can have a companion object with the same name.

• Objects can extend classes ...

The best content for your career. Discover unlimited learning on demand for around $1/day.