If a superclass is static and its subclass isn't, will the subclassbe static?

?

-

If a superclass is static and its subclass isn't, will the subclass be
static?

public static class A {
}

public class A1 extends A {
}
 
C

Chris Head

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

- - said:
If a superclass is static and its subclass isn't, will the subclass be
static?

public static class A {
}

public class A1 extends A {
}

Hi,
According to:
http://www.javaworld.com/javaworld/javaqa/1999-08/01-qa-static2.html
....
"You declare a top-level class at the top level as a member of a
package. Each top-level class corresponds to its own java file sporting
the same name as the class name.

A top-level class is by definition already top-level, so there is no
point in declaring it static; it is an error to do so. The compiler will
detect and report this error."

It doesn't make any sense to declare a top-level class as static,
because it's implicitly static. There is no outer class for it to carry
a "this" reference to.

Chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (MingW32)

iD8DBQFCrmXzgxSrXuMbw1YRAhZbAJ9vhNJADR8U3DZDuS/DD1e4QJkYZwCfWLsz
HtrvTUfCJgGZ8y51Lze4LoA=
=62Zh
-----END PGP SIGNATURE-----
 
P

P.Hill

- said:
If a superclass is static and its subclass isn't, will the subclass be
static?

public static class A {
}

The above is only valid when defining an inner class, so I'm thinking
you are confused about the intended meaning of the word static on a class.

-Paul
 
?

-

Chris said:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1




Hi,
According to:
http://www.javaworld.com/javaworld/javaqa/1999-08/01-qa-static2.html
...
"You declare a top-level class at the top level as a member of a
package. Each top-level class corresponds to its own java file sporting
the same name as the class name.

A top-level class is by definition already top-level, so there is no
point in declaring it static; it is an error to do so. The compiler will
detect and report this error."

It doesn't make any sense to declare a top-level class as static,
because it's implicitly static. There is no outer class for it to carry
a "this" reference to.

Chris

My mistake. I forgot to mention that class A and A1 are nested classes.
So will A1 inherit A's static?
 
K

Kevin McMurtrie

My mistake. I forgot to mention that class A and A1 are nested classes.
So will A1 inherit A's static?

No. Static isn't an attribute of a class. It changes the way the
compiler treats the class; more like a compiler shortcut.
 
T

Tor Iver Wilhelmsen

- said:
My mistake. I forgot to mention that class A and A1 are nested classes.
So will A1 inherit A's static?

Not the way you think. The non-static nested class will become an
inner class, with the synthesized reference to the parent class
object.
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top