/** * StaticExplorer.java * Jeff Ondich, 1/10/14 * * A brief exploration of static and non-static data and methods. * See Thing.java. */ import java.lang.Math; import java.util.Random; public class StaticExplorer { public static void main(String[] args) { // What can we do with no Thing objects instantiated? System.out.println("=== No Things instantiated ==="); System.out.println("Class motto: " + Thing.getClassMotto()); Thing.setClassMotto("This is the fabulous and self-referential new Thing Motto!"); System.out.println("Class motto after change: " + Thing.getClassMotto()); System.out.format("We have instantiated %d Thing objects so far.\n", Thing.getThingCount()); // System.out.println("Instance motto: " + Thing.getInstanceMotto()); System.out.println(""); // Instantiate a couple Thing objects. Now what can we do? System.out.println("=== Let's instantiate two Things ==="); Thing thingOne = new Thing(); Thing thingTwo = new Thing(); System.out.format("We have instantiated %d Thing objects so far.\n", Thing.getThingCount()); System.out.println("Thing One's instance motto: " + thingOne.getInstanceMotto()); System.out.println("Thing Two's instance motto: " + thingTwo.getInstanceMotto()); System.out.println("Thing One's class motto: " + thingOne.getClassMotto()); System.out.println("Thing Two's class motto: " + thingTwo.getClassMotto()); System.out.println(""); System.out.println("=== Change thingOne's instance and class motto, then reprint all the mottos ==="); thingOne.setInstanceMotto("I'm Thing One and I'm both proud and somewhat overbearing!"); thingOne.setClassMotto("All Hail Thing One"); System.out.println("Thing One's instance motto: " + thingOne.getInstanceMotto()); System.out.println("Thing Two's instance motto: " + thingTwo.getInstanceMotto()); System.out.println("Thing One's class motto: " + thingOne.getClassMotto()); System.out.println("Thing Two's class motto: " + thingTwo.getClassMotto()); System.out.println(""); // Standard Java classes //System.out.println("=== Examples from the standard Java library ==="); //System.out.println("Math.PI = " + Math.PI); //System.out.println("Random.nextInt(6) = " + Random.nextInt(6)); } }