anonymous inner classes

>>>Inner classes can be created within methods. This is something that GUI builders like Borland JBuilder do a great deal of when creating Event handlers.

Here is an example of such automatically generated code

buttonControl1.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseClicked(MouseEvent e) {
        buttonControl1_mouseClicked(e);
      }
    });



>>>


As you might guess an anonymous class cannot have be given a constructor by the programmer. Think about it, a constructor is a method with no return value and the same name as the class. Duh! we are talking about classes without names. An anonymous class may extend another class or implement a single interface



>>>A class defined within a method can only access fields in the enclosing method if they have been defined as final. This is because variables defined within methods normally are considered automatic, ie they only exist whilst the method is executing. Fields defined within a class created within a method may outlive the enclosing method.






I was reading above lines from link
http://www.jchq.net/certkey/0401certkey.htm

did not understand it clearly.


 Any ideas, resources,sample code,links,  highly appreciated. thanks in advance.
LVL 7
gudii9Asked:
Who is Participating?
 
CEHJConnect With a Mentor Commented:
>>why these variable defined in method called automatic

Because they are allocated and de-allocated automatically as the program runs

>>Fields defined within a class created within a method may outlive the enclosing method.

If another object gets a reference to them as it executes, it will hang on to them until they can be garbage collected
0
 
CEHJCommented:
The language spec is always the final authority on these issues:

http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#252986
0
 
gudii9Author Commented:
>>> variables defined within methods normally are considered automatic,

why these variable defined in method called automatic

>>>Fields defined within a class created within a method may outlive the enclosing method.

what it mean. please advise
0
 
CEHJCommented:
:)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.