• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Default Access

 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm confused. In Java 1.4, default access means 'package' access + superclasses. Did that change in 1.5? Thanks.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Dan Silva:
I'm confused. In Java 1.4, default access means 'package' access + superclasses. Did that change in 1.5? Thanks.


JLS, 1st ed. - 6.6.1 Determining Accessibility:
"If a class or interface type is not declared public, then it may be accessed only from within the package in which it is declared." And for members, "...we say there is default access, which is permitted only when the access occurs from within the package in which the type is declared."

JLS, 3rd ed (current). - 6.6.1 Determining Accessibility:
"If a top level class or interface type is not declared public, then it may be accessed only from within the package in which it is declared." And for members, "...we say there is default access, which is permitted only when the access occurs from within the package in which the type is declared."

I don't know what "'package' access + superclasses" means.
[ January 07, 2008: Message edited by: marc weber ]
 
Dan Silva
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was think of member access instead of class access. Member access, if it's default(protected) then it gets access to the package AS WELL AS the its super class. Is that right? I know class access is different, but for member visibility if it's marked default then it will extend to a subclass, as well as give access to the subclass, even if it's not part of the package. Sorry I'm not very good at explaining myself.
 
marc weber
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Dan Silva:
I was think of member access instead of class access. Member access, if it's default(protected) then it gets access to the package AS WELL AS the its super class. Is that right? ...


"protected" access can be specified for members, but it's not the default.

For members, the JLS says that default access is "only when the access occurs from within the package in which the type is declared."
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Default access is not the same as protected.

Default access (no access specifier): The member can be accessed from the class itself and from classes in the same package.

Protected access: The member can be accessed from the class itself, from classes in the same package and from subclasses (even when those subclasses are not in the same package).
[ January 08, 2008: Message edited by: Jesper Young ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic