This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Query :- Interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Query :- Interface" Watch "Query :- Interface" New topic
Author

Query :- Interface

Kartik Mahadevan
Ranch Hand

Joined: Feb 16, 2005
Posts: 47
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

Joined: Apr 14, 2004
Posts: 10336

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.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
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 ]

Java API Documentation
The Java Tutorial
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
[/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.


Mike Gershman
SCJP 1.4, SCWCD in process
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Query :- Interface