If JAVA wants to make the class unable to be new, it can use private to change the class constructor to private. In this way, an error will be reported when the class is new. The private constructor
If JAVA wants to make the class unable to be new, it can use private to change the constructor to private so that an error will be reported during the new class.
It is mainly used for static tools and static classes that can be called directly using the class name and static method without the need for new
Class D {private D () {} static void f () {System. out. println ("I Am a static method and do not need new. If you are new, I want to report an error to you. The class name is used directly. my name () can call me ");}/* If the class does not want to be new, you can write the constructor of the class that you do not want to be new to private. */public class Index {public static void main (String [] args) {// d a = new D (); // if new, the error D. f (); // call the static class }}