• Post Reply Bookmark Topic Watch Topic
  • New Topic

access modifiers  RSS feed

 
M Berg
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi experts,

The book says for example default access is more strict than protected, like this:
Protected access: can be used a) in same package OR b) in any child in any package.
Default access: can be used only in same package.

Can't help thinking... are these access modifiers meant more for code inheritance rather than for general use?


Many thanks,
Kind regards MB
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would say these are an access specifiers rather than access modifier[typically static, final etc...]. the access specifiers plays important role in visibility mechanism across packages.

hth
 
Campbell Ritchie
Marshal
Posts: 56576
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Java™ Language Specification says "access modifiers", so don't call them specifiers. And don't use abbreviations like "hth".
 
Vinod Vinu
Ranch Hand
Posts: 217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Java™ Language Specification says "access modifiers", so don't call them specifiers.


I don't agree with M Berg . Seetharaman Venkatasamy is very much correct.
Access specifiers and access modifiers both are two different things in java where many people often get confused.
Basically access modifiers are static, final,volatile, transient,etc which deals with fields and methods mainly. on the other side, access specifiers are your private,public,protected and default which also deals with fields and methods about their visiblities only.


And don't use abbreviations like "hth".

this time i agree with you M Berg , even i did not understand what is "hth" ? please tell me this 1st.
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vinod Vijay wrote:I don't agree with M Berg . Seetharaman Venkatasamy is very much correct.
Access specifiers and access modifiers both are two different things in java where many people often get confused.
Basically access modifiers are static, final,volatile, transient,etc which deals with fields and methods mainly. on the other side, access specifiers are your private,public,protected and default which also deals with fields and methods about their visiblities only.

In that case you don't agree with the Java language specification (as Campbell pointed out), which consistently refers to private etc. as access modifiers. As does, for example, the Sierra/Bates SCJP Study Guide.

I mean, think about it: final, transient and volatile don't have anything to do with access - how can they be access modifiers? Sierra/Bates refer to them as "Nonaccess member modifiers". The Java language spec uses "class modifiers", "field modifiers" and "method modifiers" as a more general term that includes access modifiers as a subset.

 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To answer the original question, default access is very common - allowing the classes in your package to work together without exposing the details to the outside world. protected is usually related to inheritance.

(Though I wouldn't make a distinction between "inheritance" and "general use". This is an OO language - inheritance is general use!)
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:The Java™ Language Specification says "access modifiers", so don't call them specifiers.

Ok, fine. but then what is the difference between specifier and modifier ?
Campbell Ritchie wrote:And don't use abbreviations like "hth".

I thought of this is a common word in forum. here after I will write hope this helps instead of *hth*
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not common enough; Vinod wasn't the only one who didn't know what it meant.
 
Campbell Ritchie
Marshal
Posts: 56576
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:It's not common enough; Vinod wasn't the only one who didn't know what it meant.
And the last time I told somebody off about "hth" I had to Google to see what it meant. I found several very disparate meanings, so I find it confusing too.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!