You are here

Classes defined inside of another Class

15 January, 2016 - 09:02
Available under Creative Commons-ShareAlike 4.0 International License. Download for free at http://cnx.org/contents/402b20ad-c01f-45f1-9743-05eadb1f710e@37.6

Besides fields and methods, a Java class can also contain other classes. And just like a field or method defined inside of a class, a class defined inside of another class can be static or non-static. Here is the syntax.

class X { // fields of X ... // methods of X ... /** * named class Y defined inside of class X: */ [public | protected | private] [static] [final] [abstract] class Y [ extends A] [implements B] { // fields of Y ... // methods of Y ... // classes of Y ... } }