Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

nested interface

 
Sagar kanchi
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ashwin Kumar
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
Sandeep Chhabra
Ranch Hand
Posts: 340
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"
 
Sagar kanchi
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mr.Ashwin,
Now I've thought about it I got it now.
Thank u verymuch.
 
Seb Mathe
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Ashwin Kumar
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic