Originally posted by srinivas bolloju:
Which of the following statements is true?
a) An interface can contain a nested top-level inner class.
b) An interface can contain a member inner class.
c) A member inner class can implement an interface.
d) A static method can contain a local class.
e) A static method can contain a nested top-level class.
i have written a small program to illustrate above, all the conditions are true according to me, pls help....
srinivas,
Based on your code example your conclusions are logical, but are not correct. You have assumed that class A is non-static because you did not provide a static modifier for the declaration of class A. However, all member type declarations within an interface a implicitly public and static. It is not possible to declare a non-static class within an interface.
The following code example demonstrates that a top-level nested class can be instantiated without first creating an instance of the enclosing class. However, a non-static member class can not be instantiated without first instantiating an instance of the enclosing class.
D.E is a static nested class and therefore may be instantiated without first creating an instance of class D. However, non-static member class F can not be instantiated without first creating an instance of D.
In your code example, an instance of nested class A can be instantiated without first creating an instance of interface intera. Of course, that must be the case because it is not possible to create an instance of an interface. Therefore, nested class A must be implicitly static.