• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

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.
 
Power corrupts. Absolute power xxxxxxxxxxxxxxxx is kinda neat.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic