/* StaticVariables.java CIS 160 David Klick 2004-04-28 This program demonstrates the use of static variables. */ public class StaticVariables { // variables declared outside of methods int n1 = 1; static int n2 = 2; final static int n3 = 3; // this is a constant public static void main(String[] args) { // next line won't compile because method // is static, but variable isn't static // n1 = 10; n2 = 20; // next line won't compile because you can't // change the valure of a constant (final) // n3 = 30; // next line won't compile because method // is static, but variable isn't static // System.out.println(n1); System.out.println(n2); System.out.println(n3); System.out.flush(); // not really needed } } /* Sample from one run of program: 20 3 */