What is difference between static and non-static variables
Answer:
Static | Non-static |
static method belongs to the class | non-static method belongs to an object of a class |
Static member that will be used Independently of any object of that class | A non-static a class member must be accessed only in conjunction with an object of its class |
Static member can be used by itself, without reference to a specific instance | Non-static member can only be accessed by object of a class that it belongs to |
When a member is declared static, it can be accessed before any objects of its class are created | On the other hand when member is non-static it can be only accessed by object of class where it belongs to |
Instance variables declared as static are, essentially, global variables | Non-static variable is not global variable it depends on object of same class |