Fields

Member variables in classes are called fields. Fields are used to store the internal data for a class.

Here is a very simple example of a linked list node that refers to itself:

class Node {
  Node next
  int data
}

Usage example:

Node head = new Node
head.data = 2
head.next = new Node
head.next.data = 3
Node n = head
while n
  print(n.data)  ; Prints 2 and 3
  n = n.next
endwhile

Note that it is not necessary to initialize the next reference when creating a node, because it is automatically initialized to 0, the null reference.

Next: Methods

See Also
Classes
Variables