CHAPTER 2

image

Inner Classes

In this chapter, you will learn

  • What inner classes are
  • How to declare inner classes
  • How to declare member, local, and anonymous inner classes
  • How to create objects of inner classes

What Is an Inner Class?

You have worked with classes that are members of a package. A class, which is a member of a package, is known as a top-level class. For example, Listing 2-1 shows a top-level class named TopLevel.

Listing 2-1. An Example of a Top-Level Class

// TopLevel.javapackage com.jdojo.innerclasses;public class TopLevel {       private int value = 101;       public int getValue() {               return value;       }       public ...

Get Beginning Java 8 Language Features: Lambda Expressions, Inner Classes, Th reads, I/O, Collections,and Streams now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.