In this chapter we’ll look at inheritance in Scala: how you create subclasses and override methods, the Scala equivalent of interfaces and abstract classes, and the mechanisms Scala offers for mixing in reusable behavior. We’ll finish by discussing how to pick between all the options.
Subtype Inheritance
Creating a subtype of another class
is the same as in Java. You use the extends keyword and you can prevent subclassing with the final modifier on a class definition.
Let’s suppose we want to extend the basic Customer class from earlier and create a special subtype to represent a DiscountedCustomer. A shopping ...