This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Confused on private modifier for classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Confused on private modifier for classes" Watch "Confused on private modifier for classes" New topic
Author

Confused on private modifier for classes

David Miranda
Ranch Hand

Joined: Mar 14, 2005
Posts: 34
Hi all,

When can the private modifier be used with a class? Just in inner classes?
Jesse Torres
Ranch Hand

Joined: Mar 25, 2004
Posts: 985
Originally posted by David Miranda:
Hi all,

When can the private modifier be used with a class? Just in inner classes?


The only modifiers that can be applied to top level classes are public and default (which is what you obtain when you don't type anything). You cannot mark a top level nested class with private or protected access modifiers.

A regular inner class is a member of the outer class just as instance variables and methods are; therefore, the following modifiers can be applied to an inner class:
: final
: abstract
: public
: private
: protected
: static � except static turns it into a static nested class rather than an inner class
: strictfp

Good Luck!
David Miranda
Ranch Hand

Joined: Mar 14, 2005
Posts: 34
Thanks for clearing that up Jesse!
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
[Jesse]: You cannot mark a top level nested class with private or protected access modifiers.

Arg, no - the confusing term "top level nested class" refers to static member classes, which certainly can be private or protected. This horrible, evil, stupid term (how can something be both top-level and nested?) was dropped by Sun as of JLS 2nd edition, but unfortunately there are still plenty of books that use it. If you ever see "top-level nested class" just replace it with "static member class".

[Jesse]: A regular inner class is a member of the outer class

No, inner classes include local and anonymous classes, as well as member classes. Local and anonymous classes can't be declared with any access modifiers.

So:

You cannot mark a top level class with private or protected access modifiers.

You can mark a member class (static or nonstatic) with any access modifier.

You cannot mark a local or anonymous class with any access modifiers.
[ March 14, 2005: Message edited by: Jim Yingst ]

"I'm not back." - Bill Harding, Twister
Dibbo Khan
Ranch Hand

Joined: Dec 19, 2004
Posts: 147
Hi David,

Is that you, my pal from Sweden, I didn't know you were around on Javaranch. Did you know Sun is coming out with a new cert the Sun certified Java Associate. I would work on the programmer one first though, I don't know if the market is going to take the associate level cert. seriously, so are you thinking of getting some cert.s done?

Dibbo


MCPD (Enterprise Application Developer, Windows Developer, Web Developer - .NET 2.0), MCTS (Windows Apps, Web Apps and Disbributed Applications - .NET 2.0), MCITP (Database Developer & Business Intelligence Developer - SQL Server 2005), MCAD, MSCD.net, SCJP 5, SCWCD 1.4, SCBCD, SCMAD, SCDJWS, SCJA
David Miranda
Ranch Hand

Joined: Mar 14, 2005
Posts: 34
Hi Dibbo,

Sorry, but I think you are confusing me with somebody else, I am not from Sweden. But I am serious about getting some of the certifications nailed down. I feel that I am almost ready to take the first java programmer exam.

I just received an email back from Evelyn Cartagena-Meyer with instructions on taking the Java Associate Blueprint Survey, but the link that she supplied, http://sestbt.sun.com:8047/sesCert/, is not working.

Was anyone able to get the link to work?

Also, thanks for the summary Jim!
[ March 14, 2005: Message edited by: David Miranda ]
Jay Pawar
Ranch Hand

Joined: Aug 27, 2004
Posts: 411
Hi David,
I just finished taking the survey. I see a comma in the link you provided.
[ March 14, 2005: Message edited by: Jay Pawar ]

Cheers,<br />Jay<br /> <br />(SCJP 1.4)<br />Heights of great men were not achieved in one day, they were toiling day and night while their companions slept.
 
Don't get me started about those stupid light bulbs.
 
subject: Confused on private modifier for classes