Java examples for Object Oriented Design:Static
Define static fields that occur just once, and with a single value that is shared by all instances of the given class.
class StaticDemo { public static boolean oneValueForAllObjects = false; } public class Main { public static void main (String[] args) { StaticDemo sd1 = new StaticDemo(); StaticDemo sd2 = new StaticDemo(); System.out.println(sd1.oneValueForAllObjects); System.out.println(sd2.oneValueForAllObjects); sd1.oneValueForAllObjects = true; System.out.println(sd1.oneValueForAllObjects); System.out.println(sd2.oneValueForAllObjects); }/*from w w w . jav a2 s.c o m*/ }