public class Base {
private Base instance;
private Base() {
}
public static class BaseHelper {
Base instance = new Base();
}
}
In the above example, I have one constructor with no arguments in the base class. Now I list the constructors of this class as follows:
Constructor<?>[] constructors = Base.class.getDeclaredConstructors();
System.out.println(constructors);
When I run this code, I get the following output:
[private com.Base(), com.Base(com.Base)]
This tells me that there are two constructors:
- private constructor that I declared
- public default constructor
Why is this?
source
share