| 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
|
|
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.
|
 |
 |
|
|
subject: Fields of interface - are they public?
|
|
|