File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Interfaces Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Interfaces " Watch "Interfaces " New topic


dude philips

Joined: May 13, 2005
Posts: 1

I am DudePhilips from India,a Gradute, started career in Java. I have a doubt regarding Interfaces. " Y interfaces can't be declared as protected?"

can any body please let me know?


Pressured to be Gold from coal <br />urs <br />Dude
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

Its by design. An interface is the point of communication between one program entity and any other program entity. If you restrict access to an interface, its no longer really an interface, if you follow?

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Chris Staten
Ranch Hand

Joined: Sep 24, 2004
Posts: 101
Why would we want to declare an interface as protected? If you declare an interface as protected then only the other classes in the same package (or subclasses of the interface) could access it. With an interface the whole point is to allow ANY class to implement it so that the implementing class is guaranteed to have the exact method signature as any other class that is implementing the interface. They allow us to to get around the problems associated with multiple inheritance, but stil have that method signature guarantee. this way we know how to call the method and what to expect in return.

Besides, what�s to protect in an interface? None of the methods do anything until the interface is implemented and they are themselves implemented.
Junilu Lacar

Joined: Feb 26, 2001
Posts: 6529

An interface can actually be declared as protected or private.

See 9.1.1 of the JLS:

The access modifiers protected and private pertain only to member interfaces within a directly enclosing class declaration

Junilu - [How to Ask Questions] [How to Answer Questions]
I agree. Here's the link:
subject: Interfaces
jQuery in Action, 3rd edition