What happens (if anything) when a constructor calls 'super()' without having any superclass besides Object? Like so:
public class foo implements Serializable, Comparable {
int[] startPoint;
public foo() {
super();
startPoint = {5,9};
}
}
Edit: So if this does nothing, why would anyone explicitly write that in code? Would it make any difference if I just delete that line?
It is always OK to delete the line super();
from any constructor, and there is nothing particular about the constructors of classes that extend Object
. The call of the nullary superclass constructor is always implied, so whether you write it down or not, you always get the exact same semantics.
Note that this means that if you omit a call to the superclass constructor that does something big, like start database connections or the whole GUI, all this will happen whether or not you actually write super();
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With