• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

access modifiers

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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".
 
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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*
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic