Anonymous Inner Classes?

The inner class which is declared inside the body of a method is known as the local inner classes. The class declared inside the body of a method without naming it is known as anonymous inner classes.

class popcorn
{
       public void pop
      {
           System.out.println("popcorn");
      }
}


class food
(
     popcorn p = new popcorn()
    {
          public void pop
      {
           System.out.println("anonymous popcorn");

      }
    };
)

Example 2:

button.addActionListener(new ActionListener() {
public void actionPerfored(ActionEvent e)
{
// do something.
}
});


Note:
  • Anonymous inner class have no name,and theire type must be either a subclass of the name type or the implementor of the named interface.
  • An Anonymous inner class always end with };    or
    });
  • the key to remember is that the class is always define with in a method arguments.




 

Comments

Popular posts from this blog

Bluetooth Data Transfer Example

How to Create & Extract tar.gz and tar.bz2 Files in Linux