We can just declare classes like ListNode inside other classes - as an inner class. Essentially like any other outer class. Visibility modifiers of a member class apply to access from other classes - not anything inside the containing class. Parent must declare an instance of an inner class before referencing the members of the inner class. Member classes are not visible outside the containing class.
Local classes can only refer to final fields in the parent class.
Useful when you only need a single instance of the inner class. Most frequently used in conjunction with GUI programming. The inner class would maintain a reference to the instance of the containing object. Click here to access the output from examples.stack.StackClient.