wood burning stoves*
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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
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
Sheriff

Joined: Aug 03, 2008
Posts: 9307
    
  17

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://aspose.com/file-tools
 
subject: Fields of interface - are they public?