A member variable is compared to a local variable, a base type is a method argument with a reference type, and an anonymous object
1. Comparison of member variables and local variables
The position in the class is different: The member variable, outside the method.
Local variables, within the method.
The locations in memory are different: member variables, stack memory.
Local variables, heap memory.
The life cycle is different: member variables exist as the object exists.
Local variables, which exist as the method exists.
Initialization values are different: member variables, with default initial values.
Local variable, there is no default initial value.
Note: When the member variable and local variable have the same name, the nearest rule is executed.
1 class fin{2 int n=1; 3 Public Static void Main (string[] args) {4 int n=2; 5 SYSTEM.OUT.PRINTLN (n); // Output 2 6 }7 }
2, basic types and reference types to do method parameters
Base type: The value of the formal parameter is changed without affecting the value of the actual parameter, such as an int type parameter.
Reference type: The value of the formal parameter changes, affecting the actual parameters of the value, such as: class type parameters.
3. Anonymous objects
Can only be called once, such as: "New Fin (). method ();", "Method (New Stu ());".
Older Dick Silk Self-study note--java 0 basics to rookie--015