my dog learned polymorphism
The moose likes Beginning Java and the fly likes Query :- Interface Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Query :- Interface" Watch "Query :- Interface" New topic
Author

Query :- Interface

Kartik Mahadevan
Ranch Hand

Joined: Feb 16, 2005
Posts: 44
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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Query :- Interface
 
Similar Threads
Understanding interfaces
Defining classes inside interface!
Variables in interfaces
Interface
Class Inside an Interface