rahajengdwp

Untitled

Mar 6th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. //8.12 Employee.java
  2. //Static variable used to maintain a count of the number of
  3. //Employee objects in memory.
  4.  
  5. public class Employee
  6. {
  7. private String firstName;
  8. private String lastName;
  9. private static int count = 0; //number of Employees created
  10.  
  11. public Employee1(String first, String last)
  12. {
  13. firstName=first;
  14. lastName=last;
  15. ++count; //increment static count of employees
  16. System.out.printf( "Employee constructor: %s %s; count = %d\n",
  17. firstName, lastName, count);
  18. }
  19. public String getFirstName()
  20. {
  21. return firstName;
  22. }
  23. public String getLastName()
  24. {
  25. return lastName;
  26. }
  27. public static int getCount()
  28. {
  29. return count;
  30. }
  31. } //end class Employee
Advertisement
Add Comment
Please, Sign In to add comment