A subclass object would invoke superclass constructor?
Joined: Sep 05, 2007
Hi Guys, I have a superclass with a constructor superclass(). I have a subclass that extends superclass and has its own constructor. I create an object of subclass subclass obj = new subclass();
Now my question is would this also invoke constructor for superclass??
Kelvin Chenhao Lim
Joined: Oct 20, 2007
Yes. The first statement of every class's constructor must either invoke another constructor (e.g. "this(42);") or a superclass constructor (e.g. "super(42);"). If neither is explicitly specified in your constructor code, the compiler will automatically add a call to the no-arguments superclass constructor (i.e. "super();").