/** * This simple class is used to illustrate the usage of static variables and methods * as well as the "this" keyword. * * @author alchambers * @version sp17 */ public class SimpleClass{ private static int staticVariable; // a static variable private int instanceVariable; // an instance variable /** * Creates a new object of type SimpleClass */ public SimpleClass(){ instanceVariable = 100; staticVariable = 100; System.out.println("Memory address of this object: " + this); } /** * Returns the value of the instance variable * @return The value of the instance variable */ public int getInstanceVariable(){ return instanceVariable; } /** * Sets the value of the instance variable * @param newValue The new value of the instance variable */ public void setInstanceVariable(int newValue){ instanceVariable = newValue; } /** * Returns the value of the static variable * @return The value of the static variable */ public int getStaticVariable(){ return staticVariable; } /** * Sets the value of the static variable * @param newValue The new value of the static variable */ public void setStaticVariable(int newValue){ staticVariable = newValue; } /** * A static method is not associated with any object (it's associated with * the class). Thus, a static method cannot reference any non-static variables * or methods. */ public static void staticMethod(){ // Uncomment the following lines to trigger errors // instanceVariable = -1; // getInstanceVariable(); // System.out.println("Memory address of this object: " + this); } /** * A normal (i.e. non-static) method *can* reference any static variables */ public static void normalMethod(){ staticVariable = -1; } }