Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2008

Tip: Looking for answers? Try searching our database.

private static ?

Thread view: 
Galois271@gmail.com - 21 Mar 2008 16:03 GMT
If something is declared private, then why would it also be declared
static?  I saw this being used in an inner class.

Thanks!
Lurch
Mark Space - 21 Mar 2008 16:54 GMT
> If something is declared private, then why would it also be declared
> static?  I saw this being used in an inner class.

"static" does not mean the same thing as "private" so there's no reason
not to apply both if both are needed.

For an inner class, "static" means there's no connection to the
enclosing class, and the programmer wished to remove the overhead of
maintaining the connection.  The programmer may have also been making
explicit the fact that there isn't a connection.
Roedy Green - 21 Mar 2008 16:57 GMT
>If something is declared private, then why would it also be declared
>static?  I saw this being used in an inner class.

same reason anything else would be declared static, you need only one
of them in the entire JVM, not one per object.
Signature


Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Mike Schilling - 21 Mar 2008 17:07 GMT
>> If something is declared private, then why would it also be
>> declared
[quoted text clipped - 3 lines]
> one
> of them in the entire JVM, not one per object.

Though this must be a method (or perhaps a constant), since inner
classes can't have non-constant static fiields.
Lew - 22 Mar 2008 00:29 GMT
Galois271@gmail.com wrote:
>>> If something is declared private, then why would it also be
>>> declared
>>> static?  I saw this being used in an inner class.

Roedy Green wrote:
>> same reason anything else would be declared static, you need only
>> one
>> of them in the entire JVM, not one per object.

Actually, that's not guaranteed by 'static'.  A JVM can have more than one
occurrence of a static field, or to be more precise, a JVM can load more than
one static field from the same bytecode if loaded by different loaders.

> Though this must be a method (or perhaps a constant), since inner
> classes can't have non-constant static fiields.

Actually, static methods are forbidden to inner classes also:
<http://java.sun.com/docs/books/jls/third_edition/html/classes.html#8.1.3>
> Inner classes may not declare static members,
> unless they are compile-time constant fields (§15.28).

and
<http://java.sun.com/docs/books/jls/third_edition/html/classes.html#8.1.6>
> members of the class, that is, fields (§8.3), classes (§8.5), interfaces (§8.5)
> and methods (§8.4).

Signature

Lew



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.