• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

nested interface

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Ranch Hand
Posts: 340
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Mr.Ashwin,
Now I've thought about it I got it now.
Thank u verymuch.
 
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic