0
can we call a constructor from another one? how?
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.
+ 1
thanks loads:)