When do you call super() in Java? I see it in some constructors of the derived class, but isn\'t the constructors for each of the parent class called automatically? Why woul
When you have a class that extends another class and the father class have no default constructor then you have to use super() in the Son's constructor to call the constructor in the Father Class with the proper arguments like this :
class A
{
int a;
A(int value)
{
this.a=value;
System.out.println("A Constructor " + a );
}
}
class B extends A
{
int b;
B()
{
super(5);
this.b=10;
System.out.println("B Constructor " + b);
}
}
you have to know that yo can't use "super" with "this" if you want to call another constructor in the calss using "this".