class Person { private String name; // name of current Person private Person friend; // friend of current Person // is also a Person public Person() { } // constructor // Set current Person's $name$: public void setName(String n) { name = n; } // Set current Person's $friend$: public void setFriend(Person p) { friend = p; } // Return description of current object: public String toString() { return "Name: "+name+"; Friend: "+friend.name; } } public class aggregation { public static void main(String[] args) { // create 2 new people: Person a = new Person(); Person b = new Person(); // set names of the people: a.setName("Ira"); b.setName("Able"); // make friends: a.setFriend(b); b.setFriend(a); // print descriptions: System.out.println(a); System.out.println(b); } } /* output: Name: Ira; Friend: Able Name: Able; Friend: Ira */