Author | Topic: nested class in interface |
Mani unregistered |
posted April 20, 2000 09:40 AM
A question from IBM mock exam 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 What they really mean by nested top level onner class inside an interface?? interface face } interface face }
|
maha anna bartender |
posted April 23, 2000 07:31 PM
Mani , Nested top level class means a static inner class . I am giving you an example program and Maha's comment also for you to play with. Have fun . regds maha anna
[This message has been edited by maha anna (edited April 23, 2000).]
|
Mani ranch hand |
posted April 23, 2000 11:48 PM
This code was really helpful. But one more thing. Why public final int i1 = 100; in class c1 doesn't produce any error. We are implementing inter .(as in your next line you have proved that only methods and variables of inner class are inherited,so I think we are inheriting final var i1 also.). In c1 we are trying to change the value of final static variable inherited from inter.Shouldn't it give an error??(Although it is not giving any)
|
maha anna bartender |
posted April 24, 2000 01:23 PM
Mani, Your doubt is correct. You have to understand one more point in inheritance of var. In case of var inheritance, you can re-declare the inheritad var as whatever you want. This is not like method inheritance. In method inheritance only, we have to be careful about whether we are overriding or hiding accordingly we should re-define the method in subclass. But in case of var, the subclass hides the inherited ones. JLS says this is hiding of inherited variables. JLS relaxes the ruls for var hiding . In case of method hiding we have to be careful while hiding a static method. We can't hide a static method to be non-static. But in case of var hiding we can. Refer to JLS here Classes /4th paragraph/last sentence
[This message has been edited by maha anna (edited April 24, 2000).]
|
Eric Barnhill ranch hand |
posted April 25, 2000 09:42 PM
My question is, what good is a final var in an interface then? I can see with a class, even if a subclass could change it, then it would have value within the base class. But since one always has to implement an interface, and you can change the var, final seems to me of no power . Eric B.
|
| | |