One. method
1. The method is a class of objects to complete a set of statements for a task. They are used to complete specific tasks in or other objects in this object, and use a method of functions and subroutines used in other statements. Parameter passes is the value transfer. When an object is transmitted to a parameter, the value of the parameter is the reference to the object. The content of the object can be changed in the method called, but the reference to the object cannot be changed, that is, the value of the parameter is constant.
2. The THIS key is used to point to the current object or class instance, which can use the THIS pointer in any object reference. The Java language automatically calls the instance variable, method calls with the keyword THIS. 3. Overload method In the same class or in inheritance relationship, several methods having the same behavior but different parameters constitute an overload method. Select the appropriate method according to the type and quantity of the parameters during the call. And the parameter table must have a significant difference, avoiding the semantic confusion of FLOAT to Double this, only the return value is not enough to distinguish the overload method.
4. Override method, the method defined in the subclass, its name, return value type, and parameter table are exactly the same as the name of the method in the middle of the parent class, and the return value type, and parameter table is exactly the same, and the new method will rewrite the old method. That is, behavior related to the runtime type (the type of variable referenced) is obtained, not a behavior associated with the compile time of the variable. In C , you need to add keyword Virtual, and Java is called a rewriting method. Rules for rewriting methods:
(1) The method name, the return value type, the type, number, and the order of the parameters are consistent with the method it rewritten.
(2) The rewriting method cannot be more accessibility than the rewritable method. (Public, private, protected)
(3) Rewriting method cannot throw more exceptions than the rewriting method.
two. The constructor name must be identical to the class name and does not contain the return value.
Create an object with NEW, do the following: 1) Assign the storage space for the object
2) Initialize the object instance, or assign initial value, or use the default value (number is 0, the object is NULL, the Boolean FALSE, the characters use '/ 0')
3) Call the constructor of this class. A class can have multiple constructor, which is determined which one in the New statement is determined. A class has at least one constructor. If Java automatically provides a default constructor, no parameter table, the function body is empty, can be called with the new xxx () mode. When you define a configuration function with parameters, the default constructor is lost, and it will be erroneous with the new xxx () mode. When there are multiple constructor, you can call one of the other. The parent class constructor is called before the subclass constructor in Java is executed. A specific parent class constructor can be called as part of the subclass constructor by calling the SUPER () in the subclass constructor first row. Different parameters determine which one is called. When calling with super (), call the parent class default constructor, if the parent class has no default constructor, it is wrong. In the same way, Super and this must be placed in the first line of the constructor, but it cannot be placed in the same alone.