Anonymous Object

  • Eclipse: Oxygen
  • Java: 1.8

The anonymous object simply means creating a new Object without assigning it to a reference. Hence this could be used only once in the execution of a program as it is not referenced to any object.

It is useful for writing implementation classes for listener interfaces in graphical programming.

Let us take a simple program, to understand an anonymous object.

Here, an object for Door class is not created. We can create a new Object without assigning it to a reference.

Contributed by: Poonam Tomar


Full stack Java Developer

   Buy me a coffee!

 

PayTM QR (INDIA)

Download file

Leave a Reply

avatar
  Subscribe  
Notify of
Close Menu