wood burning stoves*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes nested interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "nested interface" Watch "nested interface" New topic
Author

nested interface

Sagar kanchi
Ranch Hand

Joined: Oct 07, 2005
Posts: 50
Hi all,

I have read the we can have nested interface [ie static interface], but we cann't have non-static interface. Why? Whats the reason behind it.
Can anybody explain me. Please?


Where there are more wonders there is less knowledge
Ashwin Kumar
Greenhorn

Joined: Oct 13, 2005
Posts: 27
All members (excluding methods) of an interface are by default "public static". Thus a nested interface, which is essentially a member within the outer interface, will also be static (implicitly)


SCJP 1.4<br />SCBCD 5.0<br />SCWCD 1.4 (Preparing)
Sandeep Chhabra
Ranch Hand

Joined: Aug 28, 2005
Posts: 340
Originally posted by AshwinC Kumar:
All members (excluding methods) of an interface are by default "public static". Thus a nested interface, which is essentially a member within the outer interface, will also be static (implicitly)


Ashwin If I am not wrong, Even the methods of an interface are by default "public static"


Regards<br />Sandy<br />[SCJP 5.0 - 75%]<br />[SCWCD 1.4 - 85%]<br />------------------<br />Tiger, Tiger burning bright,<br />Like a geek who works all night,<br />What new-fangled bit or byte,<br />Could ease the hacker's weary plight?
Sagar kanchi
Ranch Hand

Joined: Oct 07, 2005
Posts: 50
Hi Mr.Ashwin,
Thanks for ur explaination. But u've talked about interface inside interface. But what abt interface inside a class. Could u explain that also in detail. Please.......
Sagar kanchi
Ranch Hand

Joined: Oct 07, 2005
Posts: 50
Thanks Mr.Ashwin,
Now I've thought about it I got it now.
Thank u verymuch.
Seb Mathe
Ranch Hand

Joined: Sep 28, 2005
Posts: 225
Sandy,


Ashwin If I am not wrong, Even the methods of an interface are by default "public static"


You're wrong : interface cannot have static methods.
interface methods are all public abstract.


Regards,<br />Seb<br /> <br />SCJP 1.4
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228

Ashwin If I am not wrong, Even the methods of an interface are by default "public static"


The methods in the interface has to be overriden by the concrete class that implements it. But static methods cannot be overriden since it belongs to a class and not to an instance.


Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
Ashwin Kumar
Greenhorn

Joined: Oct 13, 2005
Posts: 27
Hi Mr.Ashwin,
Thanks for ur explaination. But u've talked about interface inside interface. But what abt interface inside a class. Could u explain that also in detail. Please.......


When an interface is declared inside a class, it behaves as a static member of the outer class. (i.e.,)
i) It cannot access non-static members of the outer class
ii) Can be used outside the class as "<OuterClassName>.<InterfaceName>", i.e., you need not have an instance of the outerclass to access the Interface

Apart from this, it behaves as a normal interface
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: nested interface
 
Similar Threads
Static Nested Classes
INNER CLASS - Is it an error / JLS
Nested Interface?? in SCJP 1.4
top level nested interfaces
nested interface