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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.