Differences between the Instance variable Vs. the Static variables
Categories: Java 8(JDK1.8)
Now let us do discuss the differences between the Instance variable Vs. the Static variables
Each object will have its copy of the instance variable, whereas we can only have one copy of a static variable per class irrespective of how many objects we create.
Changes made in an instance variable using one object will not be reflected in other objects as each object has its own copy of the instance variable. In the case of static variable, changes will be reflected in other objects as static variables are common to all objects of a class.
We can access instance variables through object references, and static variables can be accessed directly using the class name.
Syntax: Static and instance variables
class GFG
{
// Static variable
static int a;
// Instance variable
int b;
}