Variable type according to declared location

  • Class Area

Starting point of Class ~ Ending point of Class.

Only decaration. ex) variable declaration, method declaration.

Instance Variable, Class Variable

  • Method Area

Starting point of Method ~ Ending point of Method. =>Local Variable

class Variables {
   //Class Area
   int iv;//Instance Variable
   static int cv;//Class Variable  (static variable, sharing variable)
   
   //Method Area
    void method () {
     int lv = 0;//Local Variable
     } 
}
  • Variable scope

Variable Type

Declared Location

Makint time

Class Variable

Class Area

When Class is on memory.

Even when instance(object) is not created yet.

=> Can use anytime

Instance Variable

(그냥 그 객체(인스턴스) 안에 있는 변수라고 생각하면 될듯)

Class Area

When Instance(object) is created

Local Variable

Except for Class Area

When variable is declared

Last updated