Construction Method: Literal Explanation: The method that executes synchronously when the object is constructed in new (the method name needs to be consistent with the class name). Function:1initialize a class member variable: eg:classA {intOne ; intboth ; PublicA () { This. one = 10; This. both = 20; //A is the constructor of ClassA, which assigns the member variable one and both values to 10 and 20. } } 2support for multiple construction methods, in overloaded form (depending on the parameters passed in, choose a different construction method)classB {intOne ; PublicBintmath) { This. one =Math; } //Pass in an int parameter, that is, this construction method PublicBintMath1,intmath2) { This. one = Math1 +math2; //Pass in two int parameters, that is, this construction method } } 3. The constructor method can not only initialize the member variables (in fact, this method is the same as the normal method, but the construction method can be run when the object is new, but the common method requires "object. Method Name"run on Call)4. Add: In fact, each class must have a default construction method, do not need to write and have ("public class name () {}") 5the construction method differs from the normal method:1. Format different constructor method: Modifier class name (parameter type parameter ...) {Initialize member Variable} General method: Requires a return value type2The function of different construction methods is generally used to initialize member variables; The general method depends on the demand; 3Called when the object is created by different constructor methods, or this ()Super() statement calls a normal method requires an object call or a static method to invoke a static method directly. 4execution of different construction methods is performed at the time of object creation and is performed only once. The general method is called by the object after it is created, and can be called multiple times.
Java Construction methods