• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Declaring an Interfaces protected

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello together,

you can declare an Interface public and with default acces (accessed only if the class is in the same package).
Why isn't it possible to declare an Interface protected, so that only classes and interfaces in the same package or interfaces which extends other interfaces, can use the members of the protected interface?

kind regards
lavond
 
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 will leave it to the experts to provide more explanation/details about this. But my understanding is that all top level classes and interfaces in java could only have public or default access. protected and private is not allowed. So what you are saying is also applicable to top level classes. Sometimes it seems like we have to accept things blindly without questioning them...unfortunately. But I hope someone will have a more convincing answer.
 
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I agree with you Larry.
 
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Lavond,
Because we need to implement the interface from out of the package also.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ast Lavond wrote:
Why isn't it possible to declare an Interface protected, so that only classes and interfaces in the same package or interfaces which extends other interfaces, can use the members of the protected interface?



*Suppose* Interface A(which is declared as protected) is in under foo package . Interface B(which needs A to extends) is in bar package . so can B extends A ? No, A wont visible in Interface B package . to make it visible A needs to be public .

IMO, declaring toplevel classes and Interface as private or protected wont make sense
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Larry Olson wrote: Sometimes it seems like we have to accept things blindly without questioning them...unfortunately.



Partly , I Agree . If you want to play cricket, you need to follow certain rules without arising question
 
Ast Lavond
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
many thanks for the replys.

Simran Dass wrote:
Because we need to implement the interface from out of the package also.



That's why i'm confused, because the default access (which is provided for classes and interfaces) allows only package visibility. So why not a protected access?

Larry Olson wrote:
Sometimes it seems like we have to accept things blindly without questioning them...unfortunately.



You're right. Either public access or default access, a in-between is not needed.
 
Muneeswaran Balasubramanian
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Lavond,
We can make our inner interface as a private or protected.The top level elements are only public or default.For ex,


Try this we achieve the interface property.
Cheers Munees

MyBlog
 
She's out of the country right now, toppling an unauthorized dictatorship. Please leave a message with this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic