Advertisement
ilminottaken

Untitled

Oct 5th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.33 KB | None | 0 0
  1. // Fig. 8.13: EmployeeTest.java
  2. // static member demonstration.
  3.  
  4. public class EmployeeTest
  5. {
  6.     public static void main( String[] args )
  7.     {
  8.         // show that count is 0 before creating Employees
  9.         System.out.printf( "Employees before instantiation: %d\n",
  10.         Employee.getCount() );
  11.  
  12.         // create two Employees; count should be 2
  13.         Employee e1 = new Employee( "Susan", "Baker" );
  14.         Employee e2 = new Employee( "Bob", "Blue" );
  15.  
  16.         // show that count is 2 after creating two Employees
  17.         System.out.println( "\nEmployees after instantiation: " );
  18.         System.out.printf( "via e1.getCount(): %d\n",e1.getCount() );
  19.         System.out.printf( "via e2.getCount(): %d\n",e2.getCount() );
  20.         System.out.printf( "via Employee.getCount(): %d\n",
  21.             Employee.getCount());
  22.  
  23.         // get names of Employees
  24.         System.out.printf( "\nEmployee 1: %s %s\nEmployee 2: %s %s\n",
  25.             e1.getFirstName(), e1.getLastName(),
  26.             e2.getFirstName(), e2.getLastName() );
  27.  
  28.             // in this example, there is only one reference to each Employee,
  29.             // so the following two statements indicate that these objects
  30.             // are eligible for garbage collection
  31.             e1 = null;
  32.             e2 = null;
  33.     }// end main
  34. } // end class EmployeeTest
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement