Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling super() with no Superclass?

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?

like image 706
Yozarian22 Avatar asked Nov 26 '12 20:11

Yozarian22


1 Answers

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();.

like image 96
Marko Topolnik Avatar answered Sep 28 '22 12:09

Marko Topolnik