O'Reilly logo

Pragmatic Scala by Venkat Subramaniam

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Extending a Class

Extending a base class in Scala is similar to extending in Java except for two good restrictions: method overriding requires the override keyword, and only the primary constructor can pass parameters to a base constructor.

The Override annotation was introduced in Java 5 but its use is optional in Java. Scala insists that the keyword override is used when overriding a method. By requiring that keyword, Scala will help minimize errors that often arise from typos in method names. You can avoid either accidentally overriding a method unintentionally or writing a new method when your intent was to override a base method.

In Scala, auxiliary constructors have to call either the primary constructor or another auxiliary constructor. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required