• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Query :- Interface

 
Kartik Mahadevan
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • 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
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • 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.
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • 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 ]
 
Mike Gershman
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic