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

Regarding Interfaces

Poushi Poushi
Greenhorn

Joined: Jun 24, 2008
Posts: 1
Hello Everybody,

I am new to java and while I was going through it i read that all the members inside an interface should be public.

Can anyone please tell me why we cannot give any other access modifier other than public inside an interface to method or variable.
and please don't write like it is the way java accepts i knew that but want to know why ?

wht's the logic behind that. Why cannot it be protected ?
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29245
    
139

Poushi,
An interface is meant to be a contract with the caller. Public access is also related to a contract. Protected is related to system internals.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Bill Shirley
Ranch Hand

Joined: Nov 08, 2007
Posts: 457
There's no technical reason there couldn't be, but as Joanne states it would go against the design reasons for Interfaces.

Providing an abstract class with a (sometimes abstract) protected method that should be overriden is already a mechanism available when programming.

Interfaces are for defining method implementation similarities outside of an inheritance hierarchy.

A protected method would only be invokable by subclassing, and an interface is not needed to impart that information.


Bill Shirley - bshirley - frazerbilt.com
if (Posts < 30) you.read( JavaRanchFAQ);
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regarding Interfaces
 
Similar Threads
doubt : class defined inside an interface
Abstract class and interfaces.
Interface??
Class defined inside an Interface
why variables inside interface has to final