| Author |
Declaring an Interfaces protected
|
Ast Lavond
Greenhorn
Joined: Mar 02, 2010
Posts: 16
|
|
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
|
 |
Larry Olson
Ranch Hand
Joined: Feb 03, 2009
Posts: 142
|
|
|
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.
|
 |
Simran Dass
Ranch Hand
Joined: Jan 09, 2010
Posts: 183
|
|
I agree with you Larry.
|
 |
Muneeswaran Balasubramanian
Ranch Hand
Joined: Mar 19, 2010
Posts: 138
|
|
Hi Lavond,
Because we need to implement the interface from out of the package also.
|
Cheers Munees
My Blog
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
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
Joined: Jan 28, 2008
Posts: 5575
|
|
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
Joined: Mar 02, 2010
Posts: 16
|
|
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
Joined: Mar 19, 2010
Posts: 138
|
|
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
|
 |
 |
|
|
subject: Declaring an Interfaces protected
|
|
|