    01: import java.io.*;
    02:
    03: /**
    04:    A test class to demonstrate serialization of cyclic
    05:    data structures.
    06: */
    07: public class Employee implements Serializable
    08: {
    09:    /**
    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:    }
    20:
    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:    }
    29:
    30:    public String toString()
    31:    {
    32:       return getClass().getName()
    33:          + "[name=" + name
    34:          + ",salary=" + salary
    35:          + ",buddy=" + buddy.name
    36:          + "]";
    37:    }
    38:
    39:    private String name;
    40:    private double salary;
    41:    private Employee buddy;
    42: }