• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

access specifiers

 
Kelvin Chenhao Lim
Ranch Hand
Posts: 513
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way, Java programmers don't usually use the term "friendly" to refer to default visibility. You should use the term "package private" instead.
 
Joseph Sweet
Ranch Hand
Posts: 327
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone!

Both files are in the same directory:






Eclipse says on class D, method foo():

Cannot reduce the visibility of the inherited method from A


But why??? In A, foo() is defined to be friendly. In D, it's still friendly. Where did I reduce the visibility???
 
Joseph Sweet
Ranch Hand
Posts: 327
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!
Learned something new.
 
Kelvin Chenhao Lim
Ranch Hand
Posts: 513
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interface methods are always public, even if you don't explicitly declare their visibility. Your D class must therefore declare foo() to be public.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic