Home Java Master-java Anonymous Classes

Related Tutorials


 
 

Share on Google+Share on Google+

Anonymous Classes

Advertisement
A local class that is defined without a name is known as Anonymous class.

Anonymous Classes

     

A local class that is defined without a name is known as Anonymous class. Anonymous classes are instantiated only once. We create a new class every time while executing a given anonymous class definition. Anonymous classes can be extended and can also implement an interface. In case of anonymous class, define a class right in the middle of an expression which allows us by an inner class.

The syntax of anonymous classes is as under :

new class_name ( [ argument-list ] ) {
.......
 class-body
.......
....... 
}

Anonymous classes can not be declared as static because they don't have a normal class declaration where it's possible to use static. They can't be define with modifiers like public, private, protected or static.

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 16, 2009

Related Tutorials

Discuss: Anonymous Classes  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:1
hariprakash
August 11, 2013
about anonymous classes

basically for what purpose we are using anonymous class?
DMCA.com