Your preferences have been saved!
» This program demonstrates static methods - public class StaticTest {   public static void main(String[] args) {     // fill the staff array with three Employee objects     Employee[] staff = new Employee[3];     staff[0] = new Employee("Tom", 40000);     staff[1] = new Employee("Dick", 60000);     staff[2] = new Employee("Harry", 65000);     // print out information about all Employee objects     for (Employee e : staff) {       e.setId();... 17 Feb 12 » Static field, constructor and exception - public class Main {   static Bar bar;   static {     try {       bar = new Bar();     } catch (Exception e) {       e.printStackTrace();     }   }   public static void main(String[] argv) {... 17 Feb 12 » Explicit static initialization with the static clause - class Cup {   Cup(int marker) {     System.out.println("Cup(" + marker + ")");   }   void f(int marker) {     System.out.println("f(" + marker + ")");   } } class Cups {   static Cup c1;... 17 Feb 12 » Show that you can't have static variables in a method - /**  * Show that you can't have static variables in a method, unlike C/C++  */ public class NoLocalStatics {   public static void main(String[] argv) {     NoLocalStatics t = new NoLocalStatics();     t.process();   }   void process() {     static int a = 42;      // EXPECT COMPILE ERROR... 17 Feb 12 » Show that you do inherit static fields - // Show that you do inherit static fields. /** This is the class that we extend. */ class AnOtherClass {   AnOtherClass() {     System.out.println("In AnOtherClass::<init>");   }   static int foo = 24;   static int bar() {     return 42;   }... 17 Feb 12 » Static Init Demo - /**  * Show static initializers. These are run when the class is loaded.  * If you run the main program here, you will see the static  * initializer before the "About to load class", since the class  * is loaded before main gets run. If you copy the guts of main into  * another class, the messages will come out in the "expected" order.  *  * @author Ian F. Darwin, http://www.darwinsys.com/  * @version $Id: StaticIniDemo.java,v 1.5 2004/02/09 03:33:54 ian Exp $  */... 17 Feb 12 » Using Static Variables - */ class Box {   double width;   public static int numBoxes = 0; // static variable is declared and initialized            public Box() {     width = 5.0;     numBoxes++; // numBoxes is incremented to count number of objects.   } }... 17 Feb 12 » Java static method - public class Main {   public static void main(String[] args) {     int result = add(1, 2);     System.out.println("(1+2) is : " + result);   }   public static int add(int first, int second) {     return first + second;   } } //(1+2) is : 3... 17 Feb 12 » Java static member variable example - public class Main {   public static void main(String[] args) {     Counter object1 = new Counter();     System.out.println(object1.getNumberOfObjects());     Counter object2 = new Counter();     System.out.println(object2.getNumberOfObjects());   } } class Counter {   static int counter = 0;... 17 Feb 12