• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

About class access modifiers

 
Jose Campana
Ranch Hand
Posts: 339
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Eric Daly
Ranch Hand
Posts: 143
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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 !
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Nicholas Jordan
Ranch Hand
Posts: 1282
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Collins Mbianda
Ranch Hand
Posts: 259
  • 0
  • Mark post as helpful
  • send pies
  • 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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic