john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

constructorExample garbage collection

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

  • « drupal 02 most useful modules
  • creditsystem LocalApplication.java »

Published

Jun 6, 2011

Category

java

~74 words

Tags

  • collection 1
  • constructorexample 1
  • garbage 1
  • java 252