• Post Reply Bookmark Topic Watch Topic
  • New Topic

what is Default access specifier?  RSS feed

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i got to know that we have a default type acess specifier as the fourth type of specifier.
it's also called as "package private" at times.
What does that means?
Any code or likk would be helpful!
 
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For this type of question you can generally get quicker answers by googling for something like "Java Package Private" or you can look in the Java tutorial eg http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html
 
Saloon Keeper
Posts: 7993
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It means that if you don't use the public, protected or private specifiers, your declaration will be "package private". These declarations can be accessed by the class itself (like private) and also by classes that are in the same package. They can *not* be reached by classes outside of the package.

Note that the default access specifier within interfaces is the same as the access specifier of the interface itself. So if you have a public interface, the members of that interface will also be public, even if you omit the public keyword.
 
Andy Richard
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well that's really strange that in the default mode a subclass can't access its super class variables/methods !!
And what about a class which is an "Inner Class" of a class??
can the inner class access its class' variables,?
 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andy Richard wrote:well that's really strange that in the default mode a subclass can't access its super class variables/methods !!

It can if it is the same package. If you want methods/variables to be accessible to sub classes in external packages then mark them as protected.

Andy Richard wrote:And what about a class which is an "Inner Class" of a class??
can the inner class access its class' variables,?

Why not try it and see what happens.
 
Andy Richard
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tony Docherty wrote:
Why not try it and see what happens.

it isn't accessible.. ?
:\
 
Andy Richard
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tony Docherty wrote:
It can if it is the same package. If you want methods/variables to be accessible to sub classes in external packages then mark them as protected.


you sure ??
:O
then what's the difference in protected specifier ??
 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andy Richard wrote:
Tony Docherty wrote:
Why not try it and see what happens.

it isn't accessible.. ?

Really, what code did you try?
 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andy Richard wrote:
Tony Docherty wrote:
It can if it is the same package. If you want methods/variables to be accessible to sub classes in external packages then mark them as protected.


you sure ??
:O
then what's the difference in protected specifier ??

Yes, I'm sure and the answer to your question is in my earlier post which you quoted in your reply.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!