I'm reading through some code. In the constructor it has super() but the class implements interface which of course doesn't have a constructor. So which super() it is referring to?
public class BoundingBox implements IBoundingVolume { public BoundingBox() { super(); mTransformedMin = new Number3D(); mTransformedMax = new Number3D(); mTmpMin = new Number3D(); mTmpMax = new Number3D(); mPoints = new Number3D[8]; mTmp = new Number3D[8]; mMin = new Number3D(); mMax = new Number3D(); for(int i=0; i<8; ++i) { mPoints[i] = new Number3D(); mTmp[i] = new Number3D(); } } public interface IBoundingVolume { public void calculateBounds(Geometry3D geometry); public void drawBoundingVolume(Camera camera, float[] projMatrix, float[] vMatrix, float[] mMatrix); public void transform(float[] matrix); public boolean intersectsWith(IBoundingVolume boundingVolume); public BaseObject3D getVisual(); }
super can be used to invoke immediate parent class method. super() can be used to invoke immediate parent class constructor.
The super keyword refers to superclass (parent) objects. It is used to call superclass methods, and to access the superclass constructor. The most common use of the super keyword is to eliminate the confusion between superclasses and subclasses that have methods with the same name.
We use super keyword to call the members of the Superclass. As a subclass inherits all the members (fields, methods, nested classes) from its parent and since Constructors are NOT members (They don't belong to objects.
If the SuperClass has a default Constructor there is no need to call it using"super()" explicitly, it will be invoked implicitly.
super()
refers to the extended class
(not an implemented interface). Which in this case is Object
So it will call the constructor in Object
(Which does nothing)
Super is referencing to the extended class. By default it is the Object class. The constructor in Object does nothing. In other words you can delete this line as it is not necessary.
Please also note what Oracle is saying about this topic:
If a constructor does not explicitly invoke a superclass constructor, the Java compiler automatically inserts a call to the no-argument constructor of the superclass. If the super class does not have a no-argument constructor, you will get a compile-time error. Object does have such a constructor, so if Object is the only superclass, there is no problem.
Source: http://docs.oracle.com/javase/tutorial/java/IandI/super.html
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