My question below is more theoretical than practical. From many of the available Java resources, I learned that the default constructor for a class has the following specification:
- does not accept arguments
- doesn't have
throws suggestions - has an empty body
The Java language specification does not contain a definition for the default constructor , it only claims that
If the class (definition) does not contain constructor declarations, then by default the constructor is declared implicitly (by the compiler).
Note that the implicitly declared implies that an explicitly set default constructor is possible. Let's look at the class below:
public class Point { private int x; private int y; public int getX() { return x; } public int getY() { return y; } }
For this class, the compiler will generate a lower default constructor:
public Point() { super(); }
My question is: if I, as a programmer, implemented the constructor as public Point() { } , could it be called the default constructor for the class above Point? If not, can any explicitly defined constructor be considered a default constructor ? I appreciate the answer from someone who is an expert or absolutely sure about this topic.
source share