Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
hi! can a non-static inner class contain a final static variable which is a compile time constant the Dan's mock says yes. but then we should be able to access it like new Outer().NonStaticInner.e); but this gives error instead this works. new Outer().new NonStaticInner().e); why! also can a nested interface have accesibility modifiesrs. madhur.
Originally posted by madhur jain: also can a nested interface have accesibility modifiesrs.
I think it can have any accessibility: �9.1.1 Interface Modifiers "The access modifier public is discussed... The access modifiers protected and private pertain only to member interfaces within a directly enclosing class declaration." Please correct me if I mis-read the JLS for the 2nd question
Originally posted by madhur jain: hi! but then we should be able to access it like new Outer().NonStaticInner.e); but this gives error instead this works. new Outer().new NonStaticInner().e); why! madhur.
Yes, the first syntax example does not work but the second one does. It is necessary to create an instance of the NonStaticInner class before attempting to access any member of the class. Since the constant value that you are attempting to access does exist at compile time it would have been possible to design the language such that the compile time constant can be accessed without first creating an instance of the NonStaticInner class. It appears that James Gosling didn't feel that it was worth the trouble.
Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
Madhur, Inner classes may have compile constants. That you already know. But the inner class is not static - 'NonStaticInner'. So you cannot access it directly since It is not in the scope of a static method of the enclosing class. Another anology - class instance variables cannot be accessed directly from static methods.
There are 29 Knuts in one Sickle, and 17 Sickles make up a Galleon. 42 tiny ads in a knut:
Free, earth friendly heat - from the CodeRanch trailboss