• 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

Regarding Top Level Nested Interface

 
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Angela Narain:
Below is one of the answers in JQPlus ( Question Id : 953578810580 )
> A top-level nested interface can contain static member variables

Now typically an interface contains static variables and non-static method prototypes. Does the above answer refer to the variables only or
rather what does it mean by "can contain static member variables" ?
The explanation further gives an example as :
public interface I1{
public void mA();
public interface Inner1
{
int k=10;
public void innerA();
}
}
Here from above the Inner1 is implicitly static.
What is the use of declaring the interface within another interface and why does it become implicitly static ? Ofcourse the usage like
I1.Inner1 is known but i am still not clear ?


 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Angela,
I am not really sure why you would want to use an inner interface but I do know why it is implicitly static:
Everything declared inside an interface must be static (implicitly) because an interface can never be instantiated.
That means, using your example, I can never do the following:
I1 i1 = new I1();
Therefore, I must be able to reference the inner interface (Inner1) without requiring an interface I1.
Regards,
Manfred.
reply
    Bookmark Topic Watch Topic
  • New Topic