File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Fields of interface - are they public? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Fields of interface - are they public?" Watch "Fields of interface - are they public?" New topic
Author

Fields of interface - are they public?

Piotr Kowalsky
Greenhorn

Joined: Jan 30, 2010
Posts: 20
I read that all methods of interface are public, even if we don't write it explicitly. Is the same with fields/variables or are they just/only static and final?
Minhaj Mehmood
Ranch Hand

Joined: Jan 22, 2007
Posts: 400

Yes that's true an interface can have only public methods and as well as public variables only, Non-public modifiers are not valid for a method/field inside java Interface.
therefore even you cannot define explicitly private/protected modified with any of interface method/field, they are by default public.


SCJP6 96% | SCWCD5 81% | SCDJWS5 79%
saima kanwal
Ranch Hand

Joined: Oct 05, 2009
Posts: 148
An interface has methods that are implicitly public and abstract , and variables that are implicitly public abstract and final, which means that an interface can declare only constants.


SCJP 6.0 (86%) SCWCD 5 (94%)
saima kanwal
Ranch Hand

Joined: Oct 05, 2009
Posts: 148
saima kanwal wrote:An interface has methods that are implicitly public and abstract , and variables that are implicitly public abstract and final, which means that an interface can declare only constants.[/quo


An interface has methods that are implicitly public and abstract , and variables that are implicitly public static and final, which means that an interface can declare only constants. ( sorry i wrote abstract instead of static in my previous post, so corrected it now )
Ankit Garg
Saloon Keeper

Joined: Aug 03, 2008
Posts: 9189
    
    2

saima if you write something wrong, then instead of posting the same thing again, you can use the button to edit your post and rectify your mistake...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Piotr Kowalsky
Greenhorn

Joined: Jan 30, 2010
Posts: 20
OK, I understand. Thanks for the answers!
Piotr Kowalsky
Greenhorn

Joined: Jan 30, 2010
Posts: 20
saima kanwal wrote:and variables that are implicitly public abstract and final,


Of course, you mean public static and final.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Fields of interface - are they public?
 
Similar Threads
interface final members
Usage of members in Interface and Abstract
Can an interface define required static functions?
classes inside an interface
package (default) access interface declarations