// // ListNode class public class ListNode { private String data; private ListNode link; public ListNode() { data = null; link = null; } public ListNode(String d, ListNode l) { data = d; link = l; } public void setData(String d) { data = d; } public void setLink(ListNode l) { link = l; } public String getData() { return data; } public ListNode getLink() { return link; } public static void main(String[] args) { ListNode head = new ListNode(); head.setData("Jon"); ListNode temp = new ListNode("Smith", head); head = temp; temp = temp.getLink(); ListNode temp1 = new ListNode("Lee", null); temp.setLink(temp1); // out the third one? System.out.println(temp.getLink().getData()); // out the second one? System.out.println(temp.getData()); // out the first? System.out.println(head.getData()); } }