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...@xxxxxxx> 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@xxxxxxx

.



Relevant Pages

  • Re: what is the RIGHT THING to make a constructor of a subclass, using super()
    ... If you are left with that requirement as a necessary or desirable part of the design, then the usual approach is probably to write a static method in the class that you call as an argument to the call to super() from your constructor. ... public Customer(String firstName, String lastName) { ... public class SlashSeparatedCustomer extends Customer { ...
    (comp.lang.java.programmer)
  • Re: what is the RIGHT THING to make a constructor of a subclass, using super()
    ... If you are left with that requirement as a necessary or desirable part of the design, then the usual approach is probably to write a static method in the class that you call as an argument to the call to super() from your constructor. ... public Customer(String firstName, String lastName) { ... public class SlashSeparatedCustomer extends Customer { ...
    (comp.lang.java.programmer)
  • Re: "x.constructor == Foo" vs "x instanceof Foo"
    ... statement does not add Super.prototype to the prototype chain of Sub ... Sub.prototype = new Super(); ... var sub1 = new Sub; ... not from constructor objects. ...
    (comp.lang.javascript)
  • Re: [General]acces of members of subclass
    ... I speak a little French and I thought "membre" was a direct translation of the English "member", and many people make the same confusion in English that you did, so I suspect it's not a translation problem. ... Super sub = new Sub; ... such "super constructor" must start with super ... public class Sub extends Super ...
    (comp.lang.java.help)
  • Re: Is method(super) legal?
    ... I try to compile but the error message: ... No. super can only be called from ... the constructor, ...
    (comp.lang.java.programmer)