Ramya, All interface methods are public and abstract implicitly and the variables are public , static , final. I doubt if there are any rules for inner class within an interface. [ March 03, 2005: Message edited by: Jay Pawar ]
Cheers,<br />Jay<br /> <br />(SCJP 1.4)<br />Heights of great men were not achieved in one day, they were toiling day and night while their companions slept.
So, you can call a method declared in the interface. Note, that the method() in NestedClass must be marked public, since it is implicitly declared public in EnclosingInterface (cannot have weaker access privileges).
[ March 07, 2005: Message edited by: Maciej Gulak ] [ March 07, 2005: Message edited by: Maciej Gulak ]
Originally posted by ramya jp: [QB]A class inside an interface is always public and static and cannot call the methods declared in the interface...compiles without an error,even though the inner class A is abstract.QB]
True. The class inside an interface is always public and static. To prove that it's public, try compiling it with a "private" qualifier. The compiler will tell you that it has to be "public".
To prove it's static (the dreaded static nested class), compile it with the static keyword, and run javap A on it. Look at the results. Then compile it without the static keyword. run javap A on it. Compare the results. It's the same bytecode!!!
To answer your question why your example compiles correctly, you've shown an example of a nested class in an interface. The compiler compiles it as a static and public class. Your class just happened to be an abstract class. It's still public and static. It just happens to be abstract.
If you want to write some code that proves the third point, write (something) like this [I don't have a compiler handy]
In this example I'm trying to call a method in the interface from a static nested class. Compiler won't allow it.
Any class you create in an interface (whether it's an abstract class or a fully implemented class) is a static nested class. Static nested classes can't access any instance methods nor variables from their "enclosing" classes.
I hope that clears that up. Furthermore K+B don't cover classes inside interfaces in their book, that should give you some idea of how relevant it is for the exam (hint: it's not, imho!).