Source of Employee.java


  1: import java.io.*;

  3: /**
  4:    A test class to demonstrate serialization of cyclic
  5:    data structures.
  6: */
  7: public class Employee implements Serializable
  8: {
  9:    /**
 10:       Constructs an employee.
 11:       @param name the employee name
 12:       @param salary the employee salary
 13:    */
 14:    public Employee(String name, double salary)
 15:    {
 16:       this.name = name;
 17:       this.salary = salary;
 18:       this.buddy = this;
 19:    }

 21:    /**
 22:       Sets the buddy of this employee
 23:       @param buddy the new buddy
 24:    */
 25:    public void setBuddy(Employee buddy)
 26:    {
 27:       this.buddy = buddy;
 28:    }

 30:    public String toString()
 31:    {
 32:       return getClass().getName() 
 33:          + "[name=" + name
 34:          + ",salary=" + salary
 35:          + ",buddy=" + buddy.name
 36:          + "]";
 37:    }

 39:    private String name;
 40:    private double salary;
 41:    private Employee buddy;
 42: }