I have the following question about the instantiation of anonymous inner classes.
given the following code :
The output is:
Subclass: s = "Hello"
x.s = "Hello" I understand the following:
- An anonymous inner class declaration effectively creates a subclass of the declared type. This is apparent given the output of the program - the overridden
aMethod() is called.
- An anonymous inner class declaration cannot have a constructor.
- Constructors cannot be inherited, and therefore cannot be overridden.
What I'd like to know is how initialisation occurs when a parameter is passed to the anonymous inner class. (In the above code the parameter is the
String "Hello").
Since the anonymous inner class has no constructor, and no explicit call is made to the superclass via
super(), how then is the String member variable (
s) correctly initialised with the given "Hello" parameter ? Does the anonymous class simply "use" the constructor of its parent ?
[ May 03, 2003: Message edited by: Rory French ]