• 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

Confused on private modifier for classes

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

When can the private modifier be used with a class? Just in inner classes?
 
Ranch Hand
Posts: 985
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for clearing that up Jesse!
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[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 ]
 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
David Miranda
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic