Get your three‑paremeter constructor working first. I shall explain “this.i” later, so you may have to read these posts in reverse order.
Earlier, I wrote: . . . There are two bits of syntax I shall tell you about, which you are probably not familiar with.
. . .
Both of them involve the keyword this.
If you do not write a call to another constructor at the beginning of your constructor, the compiler will add it for you. Usually what happens is that a constructor like this:-
… is treated by the compiler as if you had written this:-
Those two constructors would produce exactly the same bytecode output.
The super() call tells the JVM to look for the superclass' constructor, which in this case means
this constructor. The JVM calls that constructor, too, when it initialises you object.
Now, you can call another constructor instead if you wish. You might say
super(i); if you have a superclass' constructor which can take
i as an argument. But in this case you don't have such a constructor you can call, so you can't. But what you can do (as the
Java Tutorials link tells you), is have several constructors in the same class. Now you can call one constructor from another. And you do it with the keyword
this and round brackets/parentheses. Like
this();
If you write
super(...); or
this(...); that bit has to be the very first part of the constructor, so you can only ever fit one of those things in a constructor.
What
this(...); means is, “Look for another constructor in the same class which can take those arguments, call it, then come back here.” You can write a constructor which contains
this(...); and nothing else. You can write a constructor in my Foo class like this:-
What you are doing is saying, “If nobody wishes to pass any values, I'll permit that and provide default values 3, 4 and 5.”
Obviously you can have a constructor with two parameters which calls a three‑parameter constructor and copies the values of two of the parameters and provides the value of the third, too. You can include a formula in a
this(...); call.
In that case I would set
k to half the product of
i and
j. You can even have a method call
… and use that √ for
k.
I would draw your attention to methods of the Math class. Have close look at its
methods, especially those beginning with H‑Y (hint! hint!). I don't think I should say any more.