• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Inner Interface?

 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have stumbled and falled over this question I've made in a test-exam:

"Which of the following access modifiers can be used for an interface that is embedded inside an enclosing class?"

Now I remember reading about inter classes, and then I know, from the book that all acces modifiers can apply, but can you define an interface as a member of a class? Normally you do not define an interface as part of a class, but as a separate piece of code, just like a class, or am I totally confused now? Also I wonder what use could it ever have, although the latter is not really relevant concerning passing the exam.

Kind Regards. Marc
 
Ranch Hand
Posts: 332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes you can and it is implicit static member of class.



You may consider some interface closely related to specific class. For example all your inner classes are implementing it and it makes no sense for any other class outside outer class. So you put your inteface inside to make your code look a bit nicer.

I also think, that top-level interfaces are more common.
 
He was expelled for perverse baking experiments. This tiny ad is a model student:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic