public class ConstructorExample
{
static String outputtext;
public ConstructorExample()
{
System.out.println( "default constructor");
outputtext = "nothing changed";
}
public ConstructorExample( String specific )
{
System.out.println( "overloaded constructor");
outputtext = specific;
}
public void display()
{
System.out.println( outputtext );
}
protected void finalize()
{
System.out.println( "cleanup before garbage collection");
}
//future improvement: separate main and objects to allow parallel development
public static void main( String args[] )
{
ConstructorExample myExample = new ConstructorExample();
myExample.display();
ConstructorExample myExample2 = new ConstructorExample( "parameter passed");
myExample2.display();
myExample = null;
System.gc(); //explicitly force java garbage collection
}
}//end class