Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. // Static variable used to maintain a count of the number of
  2. // Employee objects in memory
  3.  
  4. public class Employee
  5. {
  6. private String firstName;
  7. private String lastName;
  8. private static int count = 0; // number of Employees created
  9.  
  10. // initialize Employee, add 1 to static count and
  11. // output String indicating that constructor was called
  12. public Employee( String first, String last )
  13. {
  14. firstName = first;
  15. lastName = last;
  16.  
  17. ++count; //increment static count of employees
  18. System.out.printf( "Employee constructor: %s %s; count = %d\n",
  19. firstName, lastName, count );
  20. }// end Employee constructor
  21.  
  22. // get first name
  23. public String getFirstName()
  24. {
  25. return firstName;
  26. }// end method getFirstName
  27.  
  28. // get last name
  29. public String getLastName()
  30. {
  31. return lastName;
  32. }// end method getLastName
  33.  
  34. // static method to get static count value
  35. public static int getCount()
  36. {
  37. return count;
  38. } // end method getCount
  39. } // end class Employee