GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes About class access modifiers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "About class access modifiers" Watch "About class access modifiers" New topic
Author

About class access modifiers

Jose Campana
Ranch Hand

Joined: May 28, 2007
Posts: 339
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

Joined: Jul 11, 2006
Posts: 143
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.


Studying for SCJP 6
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

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 ]

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Jose Campana
Ranch Hand

Joined: May 28, 2007
Posts: 339
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

Joined: Nov 29, 2005
Posts: 2308
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.


Rahul Bhattacharjee
LinkedIn - Blog
Nicholas Jordan
Ranch Hand

Joined: Sep 17, 2006
Posts: 1282
[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.


"The differential equations that describe dynamic interactions of power generators are similar to that of the gravitational interplay among celestial bodies, which is chaotic in nature."
Collins Mbianda
Ranch Hand

Joined: Aug 11, 2007
Posts: 259
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.


SCJP 5.0 | SCWCD 1.4
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: About class access modifiers