Member variables and static variables, the distinction between local variables

First, the difference between the member variables and static variables

   1, belongs to a different: an object belonging to member variables, also known as instance variables

                          Static variables belong to the class, also known as class variables

   2 different memory location: member variables are stored in the heap memory

                                     Static Static variables are stored in the method area area

   3, memory occurs at different times: with the member variables to create an object exists, the object disappear with the disappearance

                                        Static variables with loading and load class, disappear with the disappearance of the class

   4, call different: member variables can only be invoked by an object

                           Static variables can be invoked by class name, it can also be invoked through objects

Second, the difference between the member variables and local variables

   1, positions different classes: an outer member variable in the class method

                                 Local variables declared in the method or methods defined

   2 different memory location: member variables in heap memory

                                     Local variables on the stack memory

   3, different life cycle: create member variables with objects exist

                                 Local variables of the call method exists

   4, initialization value: member variables default initialization value

                             Local variables must be defined assignment

 

Published 24 original articles · won praise 11 · views 2046

Guess you like

Origin blog.csdn.net/weixin_43791069/article/details/104590738