Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

interface question

 
Vad Fogel
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, here's a question. Who can explain what's going on there?
 
Barkat Mardhani
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 504
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Vad Fogel
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Steve, I believe it's true as per JLS.
 
Asha Sat
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic