Next page | Contents page |

Inner classes

Classes may be declared inside other ones:

	public class X
	{
		A a;
		public void b () { ... }

		public class Y
		{
			U u;
			public void v () { ... }
		}
	}

This code must still be saved in X.java but the compiler creates 2 class files: X.class and X$Y.class

Outside X, class Y is referred to as X.Y and objects of that class may be used:

	X.Y y = new X.Y ();
	y.u = ...;

Y has access to all fields and methods of X, even private ones

Next page | Contents page |