Advertisement
AkramAbd

8.13 Static member demonstration

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