SE450: Inner Classes: Definitions and Static [10/22] ![]() ![]() ![]() |
In Java, classes and interfaces can be members of other classes and interfaces. These are considered nested classes and nested interfaces. They are part of the contract of their enclosing type.
Nested classes and interfaces can be assigned the same access as other members of a class.
The simplest nested class to talk about is a static nested class - technically called a top-level nested class (but this is a terribly confusing name). Static nested classes aren't inner classes.
public class BankAccount { private long number; private long balance; public static class Permissions { public boolean canDeposit, canWithdraw, canClose; } // ... }
The full name of this class is BankAccount.Permissions
.
static inner classes can be intantiated without creating an instance of the outer class. They make sense when used as a namespace mechanism more than anything. They can have any level of accessibility