6.9. Nested classes (Java inner classes)

C# allows you to write inner classes too. However, the rules are much simpler than in Java [16] when it comes to this. Java allows you to write four types of inner classes:

[16] Java has complex access privileges and scope for inner classes indeed.

  • static inner classes;

  • member inner classes (non-static inner classes – also known as nested classes);

  • local inner classes (a class within a method);

  • anonymous inner classes [17] (a class within a method without a name).

    [17] This type of Java inner class is very commonly used in AWT and Swing.

The first two are inner classes declared at class scope, while the others are inner classes declared at method scope. C# only supports the second type of inner classes (nested ...

Get From Java to C#: A Developer's Guide 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.