// We'll use instances of this object in main() below. class ListItem { String data; ListItem next; } public class StrangeExample { public static void main (String[] argv) { // Make one instance and put a string in the data field. ListItem first = new ListItem(); first.data = "Yes minister"; // Make a second one. ListItem second = new ListItem(); second.data = "Seinfeld"; // Now link them: make the first one point to the second. first.next = second; // Make a third and make the second point to the third. ListItem third = new ListItem(); third.data = "Cheers"; second.next = third; // Make a fourth etc. ListItem fourth = new ListItem(); fourth.data = "Frasier"; third.next = fourth; ListItem last = new ListItem(); last.data = "Simpsons"; fourth.next = last; // Now print. Note the extensive use of the dot-operator. System.out.println ("First: " + first.data); System.out.println ("Second: " + first.next.data); System.out.println ("Third: " + first.next.next.data); System.out.println ("Fourth: " + first.next.next.next.data); System.out.println ("Last: " + first.next.next.next.next.data); System.out.println ("Last (alt): " + last.data); } }