Why call to this() must be first statement in constructor? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why call to this() must be first statement in constructor?

26th Jul 2016, 11:42 AM
Snigdha Pradhan
Snigdha Pradhan - avatar
3 Answers
0
It's required. This is a design of Java put in by the developers of the Java language. The reasoning is up for debate. Hierarchy, calling unconstructed objects, are a couple reasons.
26th Jul 2016, 11:53 AM
James
James - avatar
0
u can call super() or this() be first statement
26th Jul 2016, 11:17 PM
Hong Wei
Hong Wei - avatar
0
in case of overloading the constructors calling of those can be done through this and super .Super can get parent class constructor.whereas this refers to particular constructor in a class.Providimg both on the first line would lead to ambiguity which should be called first? These keywords should be mentioned in the first line so that calling them and it carries operations in accordance
28th Jul 2016, 2:57 AM
Manikanth Vanka
Manikanth Vanka - avatar