Re: acces of members of subclass
Lew wrote:
Lew wrote:
The call to super() is *always* present. Any given class, in the
general case, can rely on the presence of super() call. Daniel and
you are not correct.
Eric Sosman <Eric.Sos...@sun.com> wrote:
No, Mark is right, and Daniel and Lew are wrong.
I said that there was a call. I never claimed that it would always
succeed.
You said "The call to super() is *always* present," but that is
not the case. It is absent in three cases: (1) the class happens to
be java.lang.Object, (2) there is an explicit call to a superclass
constructor other than super(), or (3) the superclass has no no-
arguments constructor. Case (1) need not concern us, but case (2)
is perfectly ordinary, and case (3) is code that cannot produce a
"given class" because it won't even compile.
Lew (and the JLS) are right in saying that the compiler inserts a
call to super() if the constructor does not begin with a call to one
How can I be wrong if I said the same thing that the JLS does?
I said you "are right," did I not?
of its superclass' constructors. But that does not guarantee that the
superclass actually *has* a no-arguments constructor that can be called
as plain super(). If it doesn't, there'll be a compile-time error.
I never said otherwise.
Try it!
The error that results proves that I was correct. There cannot be an
error on a call to super() unless there's a call to super() to have an
error.
I suspect we may be in violent agreement, differing only in our
use of nomenclature. When you refer to a "given class," it seems you
mean a bunch of source code processed by javac, whether or not it can
be compiled. I take the word "class" to mean the thing loaded into
the JVM by a ClassLoader, so in my view an uncompilable source cannot
become a "class."
You are right: The compiler will decorate constructors with calls
to super() in the absence of explicit calls to superclass constructors.
I am right: Classes without calls to super() exist, and superclasses
exist that cannot be constructed via super() calls.
Peace?
--
Eric.Sosman@sun.com