File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Access Privileges of method in an interface

 
Babu Subbu
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 116
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Babu Subbu
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ohhh.. is it....
Thanks a lot for the clarification Vishy.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic