+ 1
Why we can't use this() and super() both in a constructor?
2 ответов
+ 1
Can you give an example or a code?
0
It's just a rule that deals with the requirements and make it clear enough.
The first instruction a constructor executes, is calling another constructor, once and only once. That other constructor can be a constructor of the same class, with this(), or of the superclass, with super().
If the programmer doesn't call any constructor at the beginning of a constructor, then the instruction super(); is implicitly added by the compiler.
Everything is done so that calling another constructor is done once and only once, at the beginning. (It needs to be at the beginning, because the superclass needs to finish its initialization before the current class starts computing its own.)