While I was going through the java inner class section, I read about compiler creating a separate .class file for the inner class which is in $.class format. Later I found that for every outer class constructor as well, it creates a separate .class file which is in $1.class.
Why compiler does this for constructors as well? I was wondering if there was any relation between constructors and inner classes.
public class Foo
{
Foo()
{
System.out.print("foo");
}
class Bar
{
Bar()
{
System.out.print("bar");
}
public void go()
{
System.out.print("hi");
}
} /* class Bar ends */
public static void main (String [] args)
{
Foo f = new Foo();
f.makeBar();
}
void makeBar()
{
(new Bar() {}).go();
}
}