BenitoDannes

PBO-2.1-3-Employee

Mar 6th, 2017
376
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1. /**
  2.  * Fig. 8.12: Employee.java
  3.  * Static variable used to maintain a count of the number of
  4.  * Employee objects in memory.
  5.  *
  6.  * Benito Danneswara
  7.  * 6 March 2017
  8.  */
  9.  
  10. public class Employee
  11. {
  12.     private String firstName;
  13.     private String lastName;
  14.     private static int count = 0; // number of Employees created
  15.    
  16.     // initialize Employee, add 1 to static count and
  17.     // output String indicating that constructor was called
  18.     public Employee (String first, String last)
  19.     {
  20.         firstName = first;
  21.         lastName = last;
  22.        
  23.         ++count; // increment static count of employees
  24.         System.out.printf ("Employee constructor: %s %s; count = %d\n",
  25.             firstName, lastName, count);
  26.     } // end Employee constructor
  27.    
  28.     // get first name
  29.     public String getFirstName()
  30.     {
  31.         return firstName;
  32.     } // end method getFirstName
  33.    
  34.     // get last name
  35.     public String getLastName()
  36.     {
  37.         return lastName;
  38.     } // end method getLastName()
  39.    
  40.     // static method to get static count value
  41.     public static int getCount()
  42.     {
  43.         return count;
  44.     } // end method getCount
  45. } // end class Employee
Advertisement
Add Comment
Please, Sign In to add comment