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

Default Access Modifier

Scala’s access modifier is different from Java:

  • Java defaults to package internal visibility if you don’t specify any access modifier. Scala, on the other hand, defaults to public.

  • Java provides an all-or-nothing proposition. Either it’s visible to all classes in the current package or it’s not visible to any. Scala gives fine-grained control over visibility.

  • Java’s protected is generous. It includes derived classes in any package plus any class in the current package. Scala’s protected is akin to C++ and C#—only derived classes can access it. However, you can also ask Scala for quite a liberal and flexible interpretation of protected.

  • Finally, Java encapsulation is at the class level. You can access the private

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