O'Reilly logo

Java 9 Cookbook by Nick Samoylov, Mohamed Sanaulla

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

Using inner classes

In this recipe, you will learn about three types of inner classes:

  • Inner class: This is a class defined inside another (enclosing) class. Its accessibility from outside the enclosing class is regulated by the public, protected, and private keywords. It can access the private members of the enclosing class, and the enclosing class can access the private members of its inner class.
  • Method-local inner class: This is a class defined inside a method. Its scope is restricted to within the method.
  • Anonymous inner class: This is an anonymous class defined during object instantiation.

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