• 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

About class access modifiers

 
Ranch Hand
Posts: 339
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello there ranchers around the globe.!
Since there's no question that's ever too simple or small for this forum, here it goes:

If I don't provide an access modifier when writing a class, which one will be the default access modifier provided by the JVM?

For example, which access modifier will the following class have?


Thank you very much.
 
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I hate to just give out an answer, but I will help you find it. To get started, there are four different class access modifiers. Check out this page: http://www.faqts.com/knowledge_base/view.phtml/aid/24759/fid/165
You should find what you're looking for.
 
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 Eric Daly:
...there are four different class access modifiers...


There are four access levels, but only three modifiers. The fourth access level results from using no modifier. Of the three modifiers, only one is applicable to top-level classes.

See Java Tutorial - Access Control.
[ September 22, 2007: Message edited by: marc weber ]
 
Jose Campana
Ranch Hand
Posts: 339
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello again,

Well, I was confused about the default modifier. Is it officially utilized using the keyword default?

Thank you very much !
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jose Campana:
Is it officially utilized using the keyword default?


Though there is a keyword default but its for switch , not used for specifying class access type.
nothing specified == default.

Originally posted by Jose Campana:
If I don't provide an access modifier when writing a class, which one will be the default access modifier provided by the JVM?



It something has to be provided then it would be compiler not the JVM.
JVM simply runs the bytecode provided to it.
For example the default constructor is provided by the compiler it you do not specify one.
 
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[Jose Campana:]Well, I was confused about the default modifier. Is it officially utilized using the keyword default?

No.

You do not write the word "default" ~ you just go the end of the file you are writing in, outside of whatever class you are writing in, if you need a handy place to put something ... and do not spec any public/protected/private ---> you just let the compiler figure it out.

That is called default, you do not write the name deafault.
 
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jose.

As Nicholas said, a class with default access has no modifier.

I will just add that such a class can be seen only by classes within the same package.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic