• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

interface question

 
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all, here's a question. Who can explain what's going on there?
 
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Steve, I believe it's true as per JLS.
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Who among you feels worthy enough to be my best friend? Test 1 is to read this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic