Originally posted by Shiva Mohan: The K&B book says That�s because we cannot invoke an instance method until after the super constructor has run.
Yes K&B is right. You can't call any instance thing before super class constructor runs.
My question:What they mean by super constructor?Are they mena no arg constructor?
In your case no-arg constructor because you are not explicitly calling Super class constructor.
After called this(makeRandomName()) method this(name) will call the overloaded constructor( Objectivw6263(String name)).this point only I got.Please explain the static part for me.
When you create an instance of Objectivw6263 class, then you will get instances of super class as well.
Instance things can only be accessed when all instances are created up the hierarchy.
Since in Objectivw6263() you are calling overloaded version of same class constructor, so still super class constructor is not called. So accessing any instance thing at that point will return compilation error.
Whereas static thing can be accessed because they are not part of instance rather they are part of class.
The whole point is don't allow any instance member access till all instances up the hierarchy gets created and initialised.
can you please explain again how the constructor is working in this case?Does this constructor invoke super() at first
Joined: Apr 25, 2005
Objectivw6263() will call no-arg constructor of Object class i.e., Object().
When you explicitly provide this(..) as a first line in constructor, then compiler will not insert super().
Keep it simple and short... Compiler will call no-arg constructor if no explicit superclass constructor or overloaded constructor of same class you have called.
In above code A() will not call Object(), because you are calling overloaded constructor of same class. A(String str) will call no-arg constructor of superclass in this case Object class's Object() constructor.
Remember in any constructor, first line will be either this() or super().