• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Fields of interface - are they public?

 
Piotr Kowalsky
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 400
Hibernate Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
saima kanwal
Ranch Hand
Posts: 148
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
saima kanwal
Ranch Hand
Posts: 148
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9497
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Piotr Kowalsky
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, I understand. Thanks for the answers!
 
Piotr Kowalsky
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic