Home Java Master-java Anonymous Classes



Anonymous Classes
Posted on: June 16, 2009 at 12:00 AM
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.

Related Tags for Anonymous Classes:
cclassanttimeioclassesexecdefinitionnewexecreateanonymouswhileinisseeilitinitimceinnoasstamntclesmecutsxeatinstantinstantiateimeiveaarutissstantifinonlyononlnon


More Tutorials from this section

Ask Questions?    Discuss: Anonymous Classes  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.