| Author |
Anonymous classes
|
Venkat Ramsimha
Ranch Hand
Joined: Dec 28, 2004
Posts: 127
|
|
hi all can anybody provide WHT IS ANONYMOUS CLASS AND NEED SOME SAMPLE PROGRAMS ON HOW ANONYMOUS CLASSES CAN BE DECLARED? thanks, venkat
|
 |
marc weber
Sheriff
Joined: Aug 31, 2004
Posts: 11343
|
|
A search of this board for "anonymous" provides a plethora of examples. But here's a crash course on the basics. Suppose you have a class called MyClass. To create an instance, you would say... MyClass my = new MyClass(); Now, suppose you inserted an alternative class body before the semicolon... MyClass my = new MyClass() {...}; In this case, the alternative body is that of an anonymous class that extends MyClass. (If MyClass were an interface, then the anonymous class would implement the interface.) Also, the instance reference is automatically upcast to the type MyClass. Therefore, when methods are called on this instance, polymorphism will invoke the overridden versions defined in the anonymous class body. [ May 11, 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
|
 |
 |
|
|
subject: Anonymous classes
|
|
|