Class-to-object relationships
By extracting the common characteristics and behaviors of a class of things, the feature is extracted as a property, and the behavior is extracted as a method, thus forming a class---class is the generalization of the object.
Create an instance/object of the corresponding class by using the New keyword---object is a class-specific
member variables and local variables
Difference:
1. Define the location differently. Member variables are defined outside of the method in the class. A local variable is defined within a method or statement.
2. Scopes are different. Member variables function within the entire class, and local variables function within the current method or statement defined.
3. Storage location is different. Member variables are stored in heap memory and are automatically assigned initial values in heap memory; Local variables are stored in stack memory and need to be initialized manually
4. Life cycle is different. Member variables are generated as objects are created, destroyed as objects are recycled, and are not necessarily recycled immediately after they are exhausted, but are recycled at some point in time. Local variables are created when the method or statement executes, and immediately after the execution of the method or statement is completed.
constructor function
A function that has the same name as a class in a class and does not return a value type
Constructors can be overloaded.
The constructor can write a return statement to avoid some problems that do not conform to the logic of the facts
this keyword
Which object is used, this represents which object---can be considered a virtual object---this represents a reference to the current object
Note: All non-static properties and methods in Java are called by the object.
The This statement---call other constructors in constructors in this class---the This statement must be placed in the first row of the constructor
Anonymous objects
An object without a name is called an anonymous object---when the method value is called once
An anonymous object can be passed as a parameter
Local code block
A block of code enclosed in {} inside a function or statement is called a local code block.
function---can limit the use of variables and life cycle, improve the utilization of stack memory
Java Classes and objects