Meaningless Drivel is fun!
The moose likes Java in General and the fly likes Anonymous Inner Class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Anonymous Inner Class" Watch "Anonymous Inner Class" New topic

Anonymous Inner Class

Sen George
Ranch Hand

Joined: Sep 21, 2005
Posts: 76
In the following code listing, please explain why the output " prAnon procedure" is not generated.

Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33130

Where does prAnon get called? It's just a method. If it doesn't get called, it doesn't print anything.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Bert Bates

Joined: Oct 14, 2002
Posts: 8898
moved to the intermediate forum

Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
marc weber

Joined: Aug 31, 2004
Posts: 11343

Just a guess on what might be causing the misunderstanding...

In the syntax for an anonymous inner class, the constructor call is followed by the anonymous class definition -- not the body of the constructor.

So the code within the braces does not execute with "new."

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
Sen George
Ranch Hand

Joined: Sep 21, 2005
Posts: 76
How can I incorporate a call to invoke the method defined in an anonymous class?
I agree. Here's the link:
subject: Anonymous Inner Class
It's not a secret anymore!