Syntax form
Member variables belong to classes, while local variables are variables or parameters of methods.
Storage method
Member variable belongs to the class or instance. Objects exist in heap memory, and local variables exist in stack memory.
Survival time
Member variables exist with the creation of objects, while local variables are generated with the call of methods and die with the end of method calls.
Default value
Member variable will be automatically assigned to the default value of the type (Exception: the final member variable must be explicitly assigned), while the local variable will not be automatically assigned.
Call
Static method can be called byclass.method
&&object.method
, while Instance method can only be called by the latter. Calling a static method does not require creating an object.
Restrictions on Access Class Members
Static methods only allow access to static members.
modifier final not allowed here
Math.max()
, Math.min()
. static variable: array.length
.