I always have to confuse the constructor with the method, and later find that
method, in fact, is needed to execute Java code, and the constructor,
Constructor,,, is an instance of a Class!!
Why is it?
class, we need to use the class to create the object to access its properties, because the instance needs to be invoked, but the invocation, we have to consider a problem, that is, the object is ultimately stored in memory, and when stored, our memory will need to give him another new memory space, then , how does Java open up memory space for the classes we need? This involves the Java memory mechanism, that is, we have to make a constructor for this class, and the name of the constructor must be the same as the name of the class, so that our Java compiler can recognize this class, and then give this class in memory to open up memory space, which is what we say, We manually and artificially gave him " initialization ", as in the following example:
Class Rock {
Rock () {
System.out.print ("Rock");
}
}
Thus, when we call the Rock class, our Java compiler will initialize him "automatically" in advance to open up memory space
The role of the Java constructor