Anonymous objects

Anonymous objects are the objects that are instantiated but are not stored in a reference variable.

In the example below, when a key is button(referred by the btn) is pressed, we are simply creating anonymous object of EventHandler class for just calling handle method.


\begin{lstlisting}
btn.setOnAction(new EventHandler()
{
public void handle(ActionEvent event)
{
System.out.println(''Hello World!'');
}
});
\end{lstlisting}