Загрузил Эльдар Сакаев

2. How to call one constructor from the other constructor

реклама
We can call one constructor from the other costructor by using "super" and "this" keywords.
Difference between "this" and "super"
1) this()
class B {
private int number1;
private int number2;
public B() {
sout("Hello");
}
public B(int a, int b) {
this();
this.number1 = a;
this,number2 = b;
}
}
Within a constructor, you can use the "this" keyword to invoke(вызывать) another constructor in the same class.
Скачать