The reason is that “Constructor call must be the first statement in a constructor”.
Read moreShould be the first statement in the constructor?
The Eclipse compiler says “Constructor call must be the first statement in a constructor”. So, it is not stopping you from executing logic before the call to super . It is just stopping you from executing logic that you can’t fit into a single expression. There are similar rules for calling this().11 Tem 2019
Read moreWhy super is called first in constructor?
Actually, super() is the first statement of a constructor because to make sure its superclass is fully-formed before the subclass being constructed . Even if you don’t have super() in your first statement, the compiler will add it for you!12 Mar 2017
Read moreShould super be the first line in constructor?
Subclass Constructors Invocation of a superclass constructor must be the first line in the subclass constructor. super(); … Object does have such a constructor, so if Object is the only superclass, there is no problem.
Read moreDoes Super have to be the first line in a constructor?
Historically, this() or super() must be first in a constructor . This restriction was never popular, and perceived as arbitrary. There were a number of subtle reasons, including the verification of invokespecial, that contributed to this restriction.12 Mar 2017
Read moreCan a constructor be private and how are this () and super () method used with constructor?
Yes, a constructor can be private .
Read moreWhat is the use of this () and super () statement in Java?
super keyword is used to access methods of the parent class while this is used to access methods of the current class . this is a reserved keyword in java i.e, we can’t use it as an identifier. this is used to refer current-class’s instance as well as static members.
Read more