private static ?

G

Galois271

If something is declared private, then why would it also be declared
static? I saw this being used in an inner class.

Thanks!
Lurch
 
M

Mark Space

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.
 
R

Roedy Green

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.
 
M

Mike Schilling

Roedy said:
same reason anything else would be declared static, you need only
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.
 
L

Lew

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.

Mike said:
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:
Inner classes may not declare static members,
unless they are compile-time constant fields (§15.28).

and
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top