java-member variables and local variables
a difference between the two
1, scope of action:
Member variables act on the entire class
A local variable acts on a function or statement.
, 2, in-memory location
Member variable: In heap memory, because the object exists, it exists in memory
Local variables: in-stack memory
3, Initialize value
Member variables are initialized to 0 and can be used directly
Local variables are not initialized by default and cannot be used.
two building code blocks
Function: Initialize an object
The object runs as soon as it is established and takes precedence over the constructor execution
differences from constructors:
Constructing code blocks is a uniform initialization for all objects.
The constructor is initialized to the corresponding object.
The initialization content of different object commonalities is defined in the Construction code block
{ System.out.println("Hello World!");}
Add braces to a class, call functions inside, and so on.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
java-member variables and local variables