Class Employee

Class Employee (Fig. 8.8) has instance variables firstName, lastName, birthDate and hireDate. Members firstName and lastName are references to String objects. Members birthDate and hireDate are references to Date objects. This demonstrates that a class can have as instance variables references to objects of other classes. The Employee constructor (lines 12–19) takes four parameters representing the first name, last name, birth date and hire date. The objects referenced by the parameters are assigned to the Employee object’s instance variables. When class Employee’s toString method is called, it returns a String containing the employee’s name and the String representations of the two Date objects. Each of these Strings is obtained ...

Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.