• 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

Query :- Interface

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hii
Irrespective of the fact how we define the Interface(as public or default)
Why do we always define it's methods as public while implementing the interface?

Thanks
Regards
M.Kartik
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Interface methods are implicitly public, so the public keyword is somewhat redundant. However, a member of a class with no modifier is not implicitly public.
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As Paul tries to explain, even if you leave off the public access modifier, the compiler automatically assigns all interface methods to be public. This is specified in the Java Language Specification, so the real answer to your question about why we have to do it this way is: "Because Sun said so!"

Layne
[ February 22, 2005: Message edited by: Layne Lund ]
 
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

[/B]Irrespective of the fact how we define the Interface(as public or default) Why do we always define it's methods as public while implementing the interface?[/B]


Can you think of a situation where marking the methods of a default scope interface as default instead of public would make any difference? I can't.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic