public class What {
  int number; 
  What tail; 
  public What(int number, What next) {
    this.number = number;
    this.tail = next; 
  }
}

--

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop\lab 05 c322 fall 2020
> What a = new What(3, null)
> a
What@9dd16ca
> a.number
3
> a.next
Static Error: No field in What has name 'next'
> a.tail
null


--

public class What extends Object {
  int number; 
  What tail; 
  public What(int number, What next) {
    this.number = number;
    this.tail = next; 
  }
  public String toString() { // over-riding -> dynamic method lookup 
    return "(" + this.number + " " + this.tail.toString() + ")"; 
    // reminder toString is invoked automatically in a String context
  }
}

--

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop\lab 05 c322 fall 2020
> What a = new What(1, new What(2, new What(3, new What(4, null)))); 
> a
(1 (2 (3 (4 null))))


--

public class What extends Object {
  int number; 
  What tail; 
  public What(int number, What next) {
    this.number = number;
    this.tail = next; 
  }
  public String toString() { // over-riding -> dynamic method lookup 
    return "(" + this.number + " " + this.tail.toString() + ")"; 
    // reminder toString is invoked automatically in a String context
  }
  public static String show(What what) { // this is just one function and
     if (what == null) return null; // recursively does the same thing
     else return what.number + " " + show(what.tail);    
  }
}

--

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop\lab 05 c322 fall 2020
> What a = new What(1, new What(2, new What(3, new What(4, null))));
> What.show( a )
"1 2 3 4 null"


--