So I have this code.
public class HourlyWorker extends Worker {
private int hours;
public HourlyWorker(String name, int salRate,int hours) {
super(name, salRate);
this.hours=hours;
}
@Override
void computePay() {
int pay;
if(hours<60)
{
System.out.println("haha");
pay=super.getSalRate()*hours; //CALLING SUPER HERE.
System.out.println("pay of"+super.getName()+"="+pay);
}
}
}
Now in the Worker class, I have this method getSalRate.
I was told that super shall be the first line of code in a method. But if I am here calling it in the middle(the expression given); It works just fine.
Can someone tell me, what really do you mean, when someone says that "Make Sure That Super Is The First Line Of Code
Is It just for the constructors?
The enforcement of first calling
super()only applies in constructors. Even if it’s left out, a call to the defaultsuper()constructor is inserted during compilation.