An object may contain references to other objects of the same class. It may even contain a link to itself (although this can cause problems in some cases).
As for why this is used, objects in real life can (and often) be connected to other objects of the same type. A person is associated with other persons (members of their families), a web page may link to other related web pages, etc.
A common application of such links in data structures is Nodes / Links, which are used to implement linked lists and trees. Each Node / Link contains some data, in addition to links to one or more other nodes / links associated with the current Node / Link.
class TreeNode<T> { T data; private List<TreeNode<T>> children; }
Eran
source share