1. What is the format of the construction method? What are the precautions?
A: Modifier constructor method Name (parameter list)
{
}
Note: (1) The construction method does not return a value type and does not require a write return value. Because it is for building objects, the object is created, and the method executes the end.
(2) The construction method name must be consistent with the class name.
2. Can the construction method be overloaded? Can I have a return statement inside?
A: The construction method can be overloaded, there can be no return statement.
3, there are several ways to assign a member variable? What's the difference?
Answer: three different ways.
The first approach is to assign values directly when declaring member variables;
The second way is to use the Get,set method to assign a value by means of an argument;
The third way is to assign a value when creating a variable by means of a constructor function.
4. If no construction method is specified, the compiler adds an empty construction method to the class file by default at compile time.
5, can only call in the construction method of other construction methods, through this (pass the parameter) way to call. This (pass parameter) should be put in the first place, otherwise it will error.
6, the child's construction method, the default will have a super () method, the purpose is to inherit the parent class's construction method into the subclass. This super () default top, super (pass parameter) and this (pass parameter) will be in the top side conflict, should try to avoid this situation.
Java Fundamentals Review-10 (construction method)