Forums Register Login

Confused on private modifier for classes

+Pie Number of slices to send: Send
Hi all,

When can the private modifier be used with a class? Just in inner classes?
+Pie Number of slices to send: Send
 

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!
+Pie Number of slices to send: Send
Thanks for clearing that up Jesse!
+Pie Number of slices to send: Send
[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 ]
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
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 ]
All that thinking. Doesn't it hurt? What do you think about this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 749 times.
Similar Threads
private protected??
New - Java Certification Web Site
What's the deal with private classes
restricting methods access
doubt if no public class in file whats file name
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 03:57:36.