Hi all, here's a question. Who can explain what's going on there?
Barkat Mardhani
Ranch Hand
Joined: Aug 05, 2002
Posts: 787
posted
0
Hi there, As you might have already run the program. The answer is A. Here is how I understand it: 1. class A is nested in interface. 2. it is treated like any interface var i.e. static and final 3. Test implements I 4. so Test inherits class A as an static nested class. 5. inner class B is extending A but not changing any functionality 6. B inherits doStuff() from A. 7. Object type is B, so the inherited version of doStuff() is called. Only question in my mind is that if class A is treated as a static and final member from interface, why was it allowed to be extended? [ October 02, 2003: Message edited by: Barkat Mardhani ]
Vad Fogel
Ranch Hand
Joined: Aug 25, 2003
Posts: 504
posted
0
This is exactly the point I have a question about. If an interface member variable is implicitly final, then it must remain final in the class implementing that interface. class A is apparently not final because it can be subclassed. The only solution I can offer is that class members of an interface are static, public, but not final, so interface classes kind of combine declarative features of both method and variable members. :roll:
Steve Lovelace
Ranch Hand
Joined: Sep 03, 2003
Posts: 125
posted
0
I believe that you are not declaring a variable, you are declaring a type. It's implicitly static, but not final. Look at JLS 9.5.
The Inner that is named is not the true Inner.
Vad Fogel
Ranch Hand
Joined: Aug 25, 2003
Posts: 504
posted
0
Thanks Steve, I believe it's true as per JLS.
Asha Sat
Greenhorn
Joined: Sep 29, 2003
Posts: 22
posted
0
Interfaces may contain member type declarations .A member type declaration in an interface is implicitly static and public. A member method is abstract ,public. Every field declaration in the body of an interface is implicitly public, static, and final member type declarations could be A member class or a member interface