This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Access Privileges of method in an interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Access Privileges of method in an interface" Watch "Access Privileges of method in an interface" New topic
Author

Access Privileges of method in an interface

Babu Subbu
Greenhorn

Joined: Sep 24, 2003
Posts: 9
Hi,
So far, I have been thinking that the default access privilege for a method in an interface is default.
I tried to following code snippet

and i got the following compile time error :
Test.java:50: get() in Test cannot implement get() in x; attempting to assign weaker access privileges; was public
class Test implements x {
^
1 error
But when the above code is changed as follows, it works fine.

Does this mean that the default access privilege of a method in an interface is public?
Could somebody please clarify.
Thanks
Babu
Vishy Karl
Ranch Hand

Joined: Sep 08, 2003
Posts: 116
Hi there,
All interface methods are by default public and abstract (even if you don't explicitly mention in the declaration).
Hence any class that implements the interface must declare the method to be public.
Hope it is clear now.
Good luck,
Bye.


"The man who can drive himself further once the effort gets painful is the man who will win." <br />Roger Bannister
Babu Subbu
Greenhorn

Joined: Sep 24, 2003
Posts: 9
ohhh.. is it....
Thanks a lot for the clarification Vishy.
 
 
subject: Access Privileges of method in an interface