I've encountered the following question online.
If we call one constructor from another in a class, what will happen?
Can anyone give me some hints?
in java also its possible with the power of the this keyword. check out the example given below.
public class A {
public A() {
//this("a");
System.out.println("inside default Constructor");
}
public A(String a){
this();
System.out.println("inside Constructor A");
}
}
This concept is called constructor chaining. If it's c# i found this saying it's possible Is nesting constructors (or factory methods) good, or should each do all init work
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With