aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Inner Interfaces Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Inner Interfaces" Watch "Inner Interfaces" New topic
Author

Inner Interfaces

Sahil Kapoor
Ranch Hand

Joined: Sep 12, 2009
Posts: 316
I have read a line in Khalid Mughal and it states that

"Nested Interfaces are always static ".

I executed the following and it compiled okay.


Please do confirm the above statement, is it wrong or wrongly interpreted by me ???

Thanks !!!

2) Please do consider statement

" No other static memebers, except final static fields, can be declared within a non-static member class"

This statement is given Correct. But i tried the follwing code snippet and it failed to compile.



So, please do confirm this statement too.... In my consideration , the above statement is false.

Thanks !!!

SCJP 6.0 96%

(Connecting the Dots ....)
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Sahil Rally wrote:I have read a line in Khalid Mughal and it states that

"Nested Interfaces are always static ".

I executed the following and it compiled okay.


Please do confirm the above statement, is it wrong or wrongly interpreted by me ???

Thanks !!!

2) Please do consider statement

" No other static memebers, except final static fields, can be declared within a non-static member class"

This statement is given Correct. But i tried the follwing code snippet and it failed to compile.



So, please do confirm this statement too.... In my consideration , the above statement is false.

Thanks !!!


Your first question isn't clear..

For the second, It's the problem related with the initialization of final fields.... Not related to the inner class...

Final variable should be initialized when the declared or in every Constructor of the class

Hope this helps~!


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

And since the inner class can have static final fields, rather than final field, they(static final fields) are compile time time constants. So you can't initialize them in Constructors rather than on the declaration time..

Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3007
    
    9
For the first question, nested interfaces are always implicitly static. Meaning they're automatically static even if you don't declare them as static.

For the second question, I don't understand your confusion. The statement was made that a non-static member class cannot have any static fields, unless they are either inherited or they are compile-time constants (which is what Abimaran describes). You tried to make a non-static member class with a static field. It didn't compile. The error message you get is "inner classes cannot have static declarations". So what's the problem? Mughal & Rasmussen said you can't do this, and the compiler also told you that you can't do this. M&R are correct.
Sahil Kapoor
Ranch Hand

Joined: Sep 12, 2009
Posts: 316
@both Thanks i got it !!!
Cheers!!!
Sandra Bachan
Ranch Hand

Joined: Feb 18, 2010
Posts: 434
I haven't studied inner classes yet, but what is the design logic for the Java programming language NOT to allow inner classes to have static declarations. Is there only ONE instance of an inner class, hence there is no need to have any static variables? Please clarify.


Marriage Made in Heaven
http://www.youtube.com/user/RohitWaliaWedsSonia
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Inner Interfaces