Browsed by
Category: Java

Class Variables

Class Variables

Class variables (or static variables) are declared with the static keyword within in a class, but outside a method. There can only one version of a class variable within a class and it will be shared with all instances of that class. If changes are made to a class variable, all other instances will also change.

Instance Variables

Instance Variables

Instance variables belong to the instance of a class or object and are declared within in a class, but outside a method. Every instance of a class with an instance variable will have its own copy of that instance variable. As instance variables are independent, if you make any changes to a variable those changes are not reflected in other instances of that class.