• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Fields of interface - are they public?

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 400
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 )

 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, I understand. Thanks for the answers!
 
Piotr Kowalsky
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic