Re: acces of members of subclass



Lew wrote:
On Jul 28, 1:37 pm, Mark Space <marksp...@xxxxxxxxxxxxxx> wrote:
Lew wrote:
Daniel Moyne wrote:
- Sub may have itw own typical constructor with its own parameters
where of
course super(...) is not present.
'super()' is always present, if only implicitly. If you do not provide
one, the compiler inserts a call to the no-argument 'super()' for you.
Er, lots of classes have no zero-argument constructor, so Daniel is
correct. Any given sub-class, in the general case, cannot rely on the
presence of a super() call.

From the JLS:
If a constructor body does not begin with an explicit constructor invocation and the
constructor being declared is not part of the primordial class Object, then the
constructor body is implicitly assumed by the compiler to begin with a superclass
constructor invocation "super();", an invocation of the constructor of its direct
superclass that takes no arguments.

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.

No, Mark is right, and Daniel and Lew are wrong.

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
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.
Try it!

class Super {
// Explicit constructor suppresses automatic creation of
// a no-arguments constructor:
Super(String foo) {
System.out.println("Super: foo = " + foo);
}
}

class Sub extends Super {
Sub(String foo) {
// Implicit super() call inserted here; error message
// because Super has no super()
System.out.println("Sub: foo = " foo);
}
}

--
Eric.Sosman@xxxxxxx
.



Relevant Pages

  • Re: Use the accessor! Was: Copy Constructor Usage
    ... > | books cause confusion by referring to a default constructor as if it ... > copy, implicit or otherwise? ... > | If we mean implicitly declared, compiler generated we should say so. ... As you can't call a copy-constructor without providing arguments, ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Use the accessor! Was: Copy Constructor Usage
    ... > | constructor as if it were a synonym for an implicitly declared ... > copy, implicit or otherwise? ... ctor is one that can be called without any arguments. ... name for a ctor implicitly provided by the compiler. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: implicit constructor declaration (user annoyed)
    ... > for the compiler to implicitly declare all constructors that are not ... // use of implicit default constructor ...
    (comp.lang.cpp)
  • Re: acces of members of subclass
    ... the compiler inserts a call to the no-argument 'super' for you. ... Er, lots of classes have no zero-argument constructor, so Daniel is ... constructor invocation "super;", an invocation of the constructor of its direct ... The call to super() is *always* present. ...
    (comp.lang.java.help)
  • Re: Internal constructor "visible" outside of assembly. (BUG IN COMPILER CONFIRMED, EXAC
    ... for the compiler, it looks like the function verifyMethodCall gathers the ... Mono on the other hand can resolve the string, it also finds the constructor ... public class Derived1:Base { ...
    (microsoft.public.dotnet.framework.clr)