Static and non static fields

A static field, or static class variable within a class is accessible before an instance of that class is created unlike instance variables. Instance variables (non-static variables) within a class are created when an instance of that class is created at run-time. Hence, non-static variables cannot be accessed until an instance of that class is created. Whereas, static class members can be accessed before that class is created or instantiated.

All instances of that class can access the same static variable. On the other hand, instance variables are individual/encapsulated to each instance of a class.

Leave a Comment