001package horstmann.ch07_serial1; 002import java.io.Serializable; 003 004/** 005 A test class to demonstrate serialization of cyclic 006 data structures. 007 */ 008public class Employee implements Serializable 009{ 010 private static final long serialVersionUID = 2008L; 011 /** 012 Constructs an employee. 013 @param name the employee name 014 @param salary the employee salary 015 */ 016 public Employee(String name, double salary) 017 { 018 this.name = name; 019 this.salary = salary; 020 this.buddy = this; 021 } 022 023 /** 024 Sets the buddy of this employee 025 @param buddy the new buddy 026 */ 027 public void setBuddy(Employee buddy) 028 { 029 this.buddy = buddy; 030 } 031 032 public String toString() 033 { 034 return getClass().getName() 035 + "[name=" + name 036 + ",salary=" + salary 037 + ",buddy=" + buddy.name 038 + "]"; 039 } 040 041 private String name; 042 private double salary; 043 private Employee buddy; 044}