Access Level of the constructor:
Public, protected, private, and default access level. Here, we will record the construction method modified by private.
Access Level of the private modifier constructor:
When the constructor is not declared as private, it means that only the method of the current class can be called. 1. Other constructor of the current class can be called using the this keyword. II. The member method of the current class can be called through the new statement.
The reason for declaring the constructor as private:
1. This class only contains static methods called by other classes, and there is no instance method. This means that when a class wants to call a method in this class, it does not need to create an instance of this class, that is, it does not touch the constructor of this class.
2. Do not inherit this class.
3. This class needs to encapsulate the details of its own implementation and does not allow othersProgramUse the new statement to create an instance of this class. This class provides other programs with a static method to obtain their own instances. This method is called a static factory method.
Question 1: Some people may have a question: "classes modified with abstract modifiers cannot be used to create instances. What is the difference between this and constructing access with private access permission words ?"
Question 2: The class modified by the final modifier cannot be inherited. What is the difference between this and constructing an access using the private access permission word?
Cause: the constructor using the private access restriction term limits the class, indicating that the class cannot be inherited or created.
Stract, which can be inherited and cannot be used to create instances.
final, which cannot be inherited and can be used to create instances.