Anonymous inner classes in Java
<p>Got some incomprehensible exercise in my book.</p>

<p>"Create a class with a non-default constructor (one with arguments) and no default constructor (no "no-arg" constructor). Create a second class that has a method that returns a reference to an object of the first class. Create the object that you return by making an anonymous inner class that inherits from the first class."</p>

<p>Can anyone come out with a source code?</p>

<p>Edit:
I don't understand what the final source code should look like. And I came with this one:</p>

<pre><code>class FirstClass
{
    void FirstClass( String str )
    {
        print( "NonDefaultConstructorClass.constructor(\"" + str + "\")" );
    }
}

class SecondClass
{
    FirstClass method( String str )
    {
        return new FirstClass( )
        {
            {
                print( "InnerAnonymousClass.constructor();" );
            }
        };
    }
}

public class task_7
{
    public static void main( String[] args )
    {
        SecondClass scInstance = new SecondClass( );
        FirstClass fcinstance = scInstance.method( "Ta ta ta" );
    }
}
</code></pre>
