GeeCON Prague 2014*
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


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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Access Privileges of method in an interface