When using new to create an object, it is called a function, the name of the function is called the constructor
Features of the constructor:
1. The name of the constructor must be exactly the same as the class name, including case.
2. The constructor does not write the return value, and does not write the return value, which means that even void is not written.
3. If the developer does not have any constructors, the Java virtual opportunity automatically creates a constructor with no parameters, and does nothing in this function.
4. Once a developer creates a constructor, the JVM will no longer create constructors with no parameters!.
5. Constructors can only be called with new, and cannot be invoked with objects.
6. In Java, a function with the same name can exist, as long as the function's parameter type is different, such a function is called the overload of the function.
I. An example of this pointer in a constructor and its memory model
Related examples
Memory model
Two. Common function problems in constructors
Related examples
Rn2 This method is not possible, because there is no constructor without parameters, the program is not found, so the compilation will be wrong.
Three. function overloading in constructors
Related examples
In Java, a function with the same name can exist, as long as the function's parameter type is different, this is called the function overload.
In the call process know which one to call is the line, clear parameters!
Java Learning Group 669823128
Java Object-oriented constructors