<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2FClass%2FStatic</id>
		<title>Java/Class/Static - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2FClass%2FStatic"/>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/Class/Static&amp;action=history"/>
		<updated>2026-04-21T14:17:06Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java/Class/Static&amp;diff=7135&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/Class/Static&amp;diff=7135&amp;oldid=prev"/>
				<updated>2010-06-01T06:35:56Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 06:35, 1 июня 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java/Class/Static&amp;diff=7134&amp;oldid=prev</id>
		<title> в 18:01, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/Class/Static&amp;diff=7134&amp;oldid=prev"/>
				<updated>2010-05-31T18:01:44Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Explicit static initialization with the static clause ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
// : c04:ExplicitStatic.java&lt;br /&gt;
// Explicit static initialization with the &amp;quot;static&amp;quot; clause.&lt;br /&gt;
// From &amp;quot;Thinking in Java, 3rd ed.&amp;quot; (c) Bruce Eckel 2002&lt;br /&gt;
// www.BruceEckel.ru. See copyright notice in CopyRight.txt.&lt;br /&gt;
class Cup {&lt;br /&gt;
  Cup(int marker) {&lt;br /&gt;
    System.out.println(&amp;quot;Cup(&amp;quot; + marker + &amp;quot;)&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
  void f(int marker) {&lt;br /&gt;
    System.out.println(&amp;quot;f(&amp;quot; + marker + &amp;quot;)&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
class Cups {&lt;br /&gt;
  static Cup c1;&lt;br /&gt;
  static Cup c2;&lt;br /&gt;
  static {&lt;br /&gt;
    c1 = new Cup(1);&lt;br /&gt;
    c2 = new Cup(2);&lt;br /&gt;
  }&lt;br /&gt;
  Cups() {&lt;br /&gt;
    System.out.println(&amp;quot;Cups()&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
public class ExplicitStatic {&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    System.out.println(&amp;quot;Inside main()&amp;quot;);&lt;br /&gt;
    Cups.c1.f(99); // (1)&lt;br /&gt;
  }&lt;br /&gt;
  // static Cups x = new Cups(); // (2)&lt;br /&gt;
  // static Cups y = new Cups(); // (2)&lt;br /&gt;
} ///:~&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
         &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Java static member variable example ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
public class Main {&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    Counter object1 = new Counter();&lt;br /&gt;
    System.out.println(object1.getNumberOfObjects());&lt;br /&gt;
    Counter object2 = new Counter();&lt;br /&gt;
    System.out.println(object2.getNumberOfObjects());&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
class Counter {&lt;br /&gt;
  static int counter = 0;&lt;br /&gt;
  public Counter() {&lt;br /&gt;
    counter++;&lt;br /&gt;
  }&lt;br /&gt;
  public int getNumberOfObjects() {&lt;br /&gt;
    return counter;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Java static method ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
public class Main {&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    int result = add(1, 2);&lt;br /&gt;
    System.out.println(&amp;quot;(1+2) is : &amp;quot; + result);&lt;br /&gt;
  }&lt;br /&gt;
  public static int add(int first, int second) {&lt;br /&gt;
    return first + second;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
//(1+2) is : 3&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Show that you can&amp;quot;t have static variables in a method ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
/*&lt;br /&gt;
 * Copyright (c) Ian F. Darwin, http://www.darwinsys.ru/, 1996-2002.&lt;br /&gt;
 * All rights reserved. Software written by Ian F. Darwin and others.&lt;br /&gt;
 * $Id: LICENSE,v 1.8 2004/02/09 03:33:38 ian Exp $&lt;br /&gt;
 *&lt;br /&gt;
 * Redistribution and use in source and binary forms, with or without&lt;br /&gt;
 * modification, are permitted provided that the following conditions&lt;br /&gt;
 * are met:&lt;br /&gt;
 * 1. Redistributions of source code must retain the above copyright&lt;br /&gt;
 *    notice, this list of conditions and the following disclaimer.&lt;br /&gt;
 * 2. Redistributions in binary form must reproduce the above copyright&lt;br /&gt;
 *    notice, this list of conditions and the following disclaimer in the&lt;br /&gt;
 *    documentation and/or other materials provided with the distribution.&lt;br /&gt;
 *&lt;br /&gt;
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS&amp;quot;&amp;quot;&lt;br /&gt;
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED&lt;br /&gt;
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR&lt;br /&gt;
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS&lt;br /&gt;
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR&lt;br /&gt;
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF&lt;br /&gt;
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS&lt;br /&gt;
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN&lt;br /&gt;
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)&lt;br /&gt;
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE&lt;br /&gt;
 * POSSIBILITY OF SUCH DAMAGE.&lt;br /&gt;
 * &lt;br /&gt;
 * Java, the Duke mascot, and all variants of Sun&amp;quot;s Java &amp;quot;steaming coffee&lt;br /&gt;
 * cup&amp;quot; logo are trademarks of Sun Microsystems. Sun&amp;quot;s, and James Gosling&amp;quot;s,&lt;br /&gt;
 * pioneering role in inventing and promulgating (and standardizing) the Java &lt;br /&gt;
 * language and environment is gratefully acknowledged.&lt;br /&gt;
 * &lt;br /&gt;
 * The pioneering role of Dennis Ritchie and Bjarne Stroustrup, of AT&amp;amp;T, for&lt;br /&gt;
 * inventing predecessor languages C and C++ is also gratefully acknowledged.&lt;br /&gt;
 */&lt;br /&gt;
/**&lt;br /&gt;
 * Show that you can&amp;quot;t have static variables in a method, unlike C/C++&lt;br /&gt;
 */&lt;br /&gt;
public class NoLocalStatics {&lt;br /&gt;
  public static void main(String[] argv) {&lt;br /&gt;
    NoLocalStatics t = new NoLocalStatics();&lt;br /&gt;
    t.process();&lt;br /&gt;
  }&lt;br /&gt;
  void process() {&lt;br /&gt;
    static int a = 42;      // EXPECT COMPILE ERROR&lt;br /&gt;
    System.out.println(&amp;quot;Process: &amp;quot; + a);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
         &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Show that you do inherit static fields ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
/*&lt;br /&gt;
 * Copyright (c) Ian F. Darwin, http://www.darwinsys.ru/, 1996-2002.&lt;br /&gt;
 * All rights reserved. Software written by Ian F. Darwin and others.&lt;br /&gt;
 * $Id: LICENSE,v 1.8 2004/02/09 03:33:38 ian Exp $&lt;br /&gt;
 *&lt;br /&gt;
 * Redistribution and use in source and binary forms, with or without&lt;br /&gt;
 * modification, are permitted provided that the following conditions&lt;br /&gt;
 * are met:&lt;br /&gt;
 * 1. Redistributions of source code must retain the above copyright&lt;br /&gt;
 *    notice, this list of conditions and the following disclaimer.&lt;br /&gt;
 * 2. Redistributions in binary form must reproduce the above copyright&lt;br /&gt;
 *    notice, this list of conditions and the following disclaimer in the&lt;br /&gt;
 *    documentation and/or other materials provided with the distribution.&lt;br /&gt;
 *&lt;br /&gt;
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS&amp;quot;&amp;quot;&lt;br /&gt;
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED&lt;br /&gt;
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR&lt;br /&gt;
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS&lt;br /&gt;
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR&lt;br /&gt;
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF&lt;br /&gt;
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS&lt;br /&gt;
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN&lt;br /&gt;
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)&lt;br /&gt;
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE&lt;br /&gt;
 * POSSIBILITY OF SUCH DAMAGE.&lt;br /&gt;
 * &lt;br /&gt;
 * Java, the Duke mascot, and all variants of Sun&amp;quot;s Java &amp;quot;steaming coffee&lt;br /&gt;
 * cup&amp;quot; logo are trademarks of Sun Microsystems. Sun&amp;quot;s, and James Gosling&amp;quot;s,&lt;br /&gt;
 * pioneering role in inventing and promulgating (and standardizing) the Java &lt;br /&gt;
 * language and environment is gratefully acknowledged.&lt;br /&gt;
 * &lt;br /&gt;
 * The pioneering role of Dennis Ritchie and Bjarne Stroustrup, of AT&amp;amp;T, for&lt;br /&gt;
 * inventing predecessor languages C and C++ is also gratefully acknowledged.&lt;br /&gt;
 */&lt;br /&gt;
// Show that you do inherit static fields.&lt;br /&gt;
/** This is the class that we extend. */&lt;br /&gt;
class AnOtherClass {&lt;br /&gt;
  AnOtherClass() {&lt;br /&gt;
    System.out.println(&amp;quot;In AnOtherClass::&amp;lt;init&amp;gt;&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
  static int foo = 24;&lt;br /&gt;
  static int bar() {&lt;br /&gt;
    return 42;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
/** This is the subclass */&lt;br /&gt;
public class InheritStatics extends AnOtherClass {&lt;br /&gt;
  public static void main(String[] c) {&lt;br /&gt;
    new InheritStatics().run();&lt;br /&gt;
  }&lt;br /&gt;
  public void run() {&lt;br /&gt;
    System.out.println(&amp;quot;In InheritStatics::run&amp;quot;);&lt;br /&gt;
    System.out.println(&amp;quot;Foo is &amp;quot; + foo);&lt;br /&gt;
    System.out.println(&amp;quot;Bar is &amp;quot; + bar());&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
         &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Static field, constructor and exception ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
public class Main {&lt;br /&gt;
  static Bar bar;&lt;br /&gt;
  static {&lt;br /&gt;
    try {&lt;br /&gt;
      bar = new Bar();&lt;br /&gt;
    } catch (Exception e) {&lt;br /&gt;
      e.printStackTrace();&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  public static void main(String[] argv) {&lt;br /&gt;
    System.out.println(bar);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
class Bar {&lt;br /&gt;
  public Bar() throws Exception {&lt;br /&gt;
  }&lt;br /&gt;
  public String toString() {&lt;br /&gt;
    return &amp;quot;Bar&amp;quot;;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Static Init Demo ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
/*&lt;br /&gt;
 * Copyright (c) Ian F. Darwin, http://www.darwinsys.ru/, 1996-2002.&lt;br /&gt;
 * All rights reserved. Software written by Ian F. Darwin and others.&lt;br /&gt;
 * $Id: LICENSE,v 1.8 2004/02/09 03:33:38 ian Exp $&lt;br /&gt;
 *&lt;br /&gt;
 * Redistribution and use in source and binary forms, with or without&lt;br /&gt;
 * modification, are permitted provided that the following conditions&lt;br /&gt;
 * are met:&lt;br /&gt;
 * 1. Redistributions of source code must retain the above copyright&lt;br /&gt;
 *    notice, this list of conditions and the following disclaimer.&lt;br /&gt;
 * 2. Redistributions in binary form must reproduce the above copyright&lt;br /&gt;
 *    notice, this list of conditions and the following disclaimer in the&lt;br /&gt;
 *    documentation and/or other materials provided with the distribution.&lt;br /&gt;
 *&lt;br /&gt;
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS&amp;quot;&amp;quot;&lt;br /&gt;
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED&lt;br /&gt;
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR&lt;br /&gt;
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS&lt;br /&gt;
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR&lt;br /&gt;
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF&lt;br /&gt;
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS&lt;br /&gt;
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN&lt;br /&gt;
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)&lt;br /&gt;
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE&lt;br /&gt;
 * POSSIBILITY OF SUCH DAMAGE.&lt;br /&gt;
 * &lt;br /&gt;
 * Java, the Duke mascot, and all variants of Sun&amp;quot;s Java &amp;quot;steaming coffee&lt;br /&gt;
 * cup&amp;quot; logo are trademarks of Sun Microsystems. Sun&amp;quot;s, and James Gosling&amp;quot;s,&lt;br /&gt;
 * pioneering role in inventing and promulgating (and standardizing) the Java &lt;br /&gt;
 * language and environment is gratefully acknowledged.&lt;br /&gt;
 * &lt;br /&gt;
 * The pioneering role of Dennis Ritchie and Bjarne Stroustrup, of AT&amp;amp;T, for&lt;br /&gt;
 * inventing predecessor languages C and C++ is also gratefully acknowledged.&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * Show static initializers. These are run when the class is loaded.&lt;br /&gt;
 * If you run the main program here, you will see the static&lt;br /&gt;
 * initializer before the &amp;quot;About to load class&amp;quot;, since the class&lt;br /&gt;
 * is loaded before main gets run. If you copy the guts of main into&lt;br /&gt;
 * another class, the messages will come out in the &amp;quot;expected&amp;quot; order.&lt;br /&gt;
 *&lt;br /&gt;
 * @author Ian F. Darwin, http://www.darwinsys.ru/&lt;br /&gt;
 * @version $Id: StaticIniDemo.java,v 1.5 2004/02/09 03:33:54 ian Exp $&lt;br /&gt;
 */&lt;br /&gt;
public class StaticIniDemo {&lt;br /&gt;
  /** A static initializer - called when class is loaded. */&lt;br /&gt;
  static {&lt;br /&gt;
    System.out.println(&amp;quot;In static initializer&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
  /** A constructor -- called when object is instantiated. */&lt;br /&gt;
  public StaticIniDemo() {&lt;br /&gt;
    System.out.println(&amp;quot;In Constructor&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
  public static void main(String[] a) {&lt;br /&gt;
    try {&lt;br /&gt;
      System.err.println(&amp;quot;About to load class&amp;quot;);&lt;br /&gt;
      Class c = Class.forName(&amp;quot;StaticIniDemo&amp;quot;);&lt;br /&gt;
      System.err.println(&amp;quot;About to construct instance&amp;quot;);&lt;br /&gt;
      Object sd = c.newInstance();&lt;br /&gt;
      System.err.println(&amp;quot;Object is &amp;quot; + sd);&lt;br /&gt;
    } catch (Exception e) {&lt;br /&gt;
      e.printStackTrace();&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
         &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Using Static Variables ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
/*&lt;br /&gt;
In this example, the Box class contains a static variable, numBoxes, which is incremented &lt;br /&gt;
each time a Box object is created. The main() method of the TestStaticVar class creates &lt;br /&gt;
two Box objects, then prints out the value of the static variable.&lt;br /&gt;
*/&lt;br /&gt;
class Box {&lt;br /&gt;
  double width;&lt;br /&gt;
  public static int numBoxes = 0; // static variable is declared and initialized&lt;br /&gt;
        &lt;br /&gt;
  public Box() {&lt;br /&gt;
    width = 5.0;&lt;br /&gt;
    numBoxes++; // numBoxes is incremented to count number of objects.&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
        &lt;br /&gt;
public class TestStaticVar {&lt;br /&gt;
  public static void main (String args[]) {&lt;br /&gt;
    Box box1 = new Box();&lt;br /&gt;
    Box box2 = new Box();&lt;br /&gt;
        &lt;br /&gt;
    System.out.println(&amp;quot;Number of objects = &amp;quot; + Box.numBoxes);&lt;br /&gt;
  } &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
         &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;/div&gt;</summary>
			</entry>

	</feed>