BenitoDannes

PBO-2.2-3-EmployeeTest

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