0

can we call a constructor from another one? how?

10th Oct 2016, 7:18 PM
S ss
S ss - avatar
2 Antworten
+ 2
Yes!!, lets take a simple example below: public class Tester{ int i; double j; public Tester(double j){ i = -8; this.j= j; } public Tester(int i, double j){ this(j); // this is calling the above constructor here this.i = i; } } Essentially use the "this" keyword followed by parenthesis and pass arguments if needed.
10th Oct 2016, 10:42 PM
Ousmane Diaw
+ 1
thanks loads:)
11th Oct 2016, 4:02 PM
S ss
S ss - avatar