Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. // static member demonstration.
  2.  
  3. public class EmployeeTest
  4. {
  5. public static void main( String[] args )
  6. {
  7. // show that count is 0 before creating Employees
  8. System.out.printf( "Employees before instantiation: %d\n",
  9. Employee.getCount() );
  10.  
  11. // create two Employees; count should be 2
  12. Employee e1 = new Employee( "Susan", "Baker" );
  13. Employee e2 = new Employee( "Bob", "Blue" );
  14.  
  15. // show that count is 2 after creating two Employees
  16. System.out.println( "\nEmployees after instantiation: " );
  17. System.out.printf( "via e1.getCount(): %d\n", e1.getCount() );
  18. System.out.printf( "via e2.getCount(): %d\n", e2.getCount() );
  19. System.out.printf( "via Employee.getCount(): %d\n",
  20. Employee.getCount() );
  21.  
  22. // get names of Employees
  23. System.out.printf( "\nEmployee 1: %s %s\nEmployee 2: %s %s\n",
  24. e1.getFirstName(), e1.getLastName(),
  25. e2.getFirstName(), e2.getLastName() );
  26.  
  27. // in this example, there is only one reference to each Employee,
  28. // so the following two statements indicate that these objects
  29. // are eligible for garbage collection
  30. e1 = null;
  31. e2 = null;
  32. } // end main
  33. } // end class EmployeeTest