wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes What does this do?  What is it's name? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What does this do?  What is it Watch "What does this do?  What is it New topic
Author

What does this do? What is it's name?

Jerry Kilpatrick
Greenhorn

Joined: Jan 02, 2005
Posts: 6
I came across the following code in one of the examples for the Swing Tutorial. I am not familiar with this syntax. What does it do? What is it's name?

Thanks,

Jerry



marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Jerry Kilpatrick:
... I am not familiar with this syntax. What does it do? What is it's name? ...

I'm guessing that the syntax you're referring to is the anonymous class definition.

Basically, an anonymous class looks like a constructor call, but before the closing semicolon, a class definition is slipped in with braces. The result is a class that implicitly extends the class (or implements the interface) identified after the keyword "new."

Furthermore, the instance of this anonymous class is automatically upcast to the type it extends (or implements).

In this particular case, we have an anonymous class that extends JLabel, and the new instance is upcast to type JLabel.
[ November 30, 2005: Message edited by: marc weber ]

"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
sscce.org
Jerry Kilpatrick
Greenhorn

Joined: Jan 02, 2005
Posts: 6
Marc,

Exactly the answer I was looking for.

Thanks,

Jerry
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What does this do? What is it's name?
 
Similar Threads
A flatland puzzle
Applet working in appletviewer but no browser
Having problem with these program
image blanks out... why?
Setting default size to JToolBar's Buttons