This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes interface question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "interface question" Watch "interface question" New topic
Author

interface question

Vad Fogel
Ranch Hand

Joined: Aug 25, 2003
Posts: 504
Hi all, here's a question. Who can explain what's going on there?
Barkat Mardhani
Ranch Hand

Joined: Aug 05, 2002
Posts: 787
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
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
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
Thanks Steve, I believe it's true as per JLS.
Asha Sat
Greenhorn

Joined: Sep 29, 2003
Posts: 22
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


{ Winners do what losers don't do }
 
Don't get me started about those stupid light bulbs.
 
subject: interface question
 
Similar Threads
dear all, i created a set of mock exam, please try it.
abstract class and static methods
interface questions
Interface instance?
Resolve.........