Construction method
Grammar:
public class name () {
}
1. When instantiating an object, call the default hidden parameterless constructor of the class.
2. If there is a custom constructor method, the default class's parameterless constructor is not called.
Class Name Object name =new class name ();//This is the parameterless construction method of the called Class
Class Name Object name =new class name (name,age);//This is a method to call a class with a parameter constructor
3. The method name is the same as the class name. Case sensitive
4. The construction method is not void and is considered a normal method if there is void
5. The function of the construction method is generally used to initialize the object properties
6. If you want to invoke another constructor within the constructor method use this (parameter); This must be placed in the first sentence
Method overloading
In the same class, the method names in the same parameter list (number type Order) are different from the access modifier return value.
The invocation is based on the argument list to determine the method of the specific invocation.
Multiple construction methods take advantage of the overloaded method
Scope of the variable
1. member variables and local variables
Variables that are defined in a class are called member variables.
Variables defined in a method are called local variables.
Member variables: Methods of other classes to access him, you must create an object of that class before you can pass the "." To reference.
Local variables: His scope is only within the method of the variable, so it can only be used in this method.
Note the point:
Scopes are different.
The initial values are different.
Local variables with the same name are not allowed in the same method. In different methods, you can have local variables of the same name.
Local variables can have the same name as member variables, and when used, local variables have higher precedence.
The construction method of Java basic note for Jen Baby