The this()
is only calling the constructor, in this case it is an alias of it. It is the way to call this special method called constructor. Since it is possible to have a normal method exist in the class with the same name, at the moment it is building it cannot call by name because it may be the constructor or it may be a normal method, so the name is used this()
. So in a way we can say that he’s actually calling Lista(6)
which is the other constructor. And it is in this other constructor that is initiating the array normally.
Then a constructor that has a signature, in the case without parameters, is calling the other constructor that accepts a parameter with the size. If you call the constructor without parameters that is said formally by the language of standard builder it assumes a value for you, in case it is 6.
Obviously this second constructor is not just initiating the array, the other field too, but there’s no reason to let it be configured by the programmer outside the class, so you can see.
For an execution is not a problem, but often this method main()
within this class is not suitable, it should be in class itself, it stands as a noise.
Your code has a abstraction leak (exposes the array out) and is not considered appropriate, even if it works, research more on the subject.