public class Count {
 public static void prt(String s){
    System.out.println(s);
  }
    Value v=new Value(10);
   static Value v1,v2;
  

    static{
      prt("v1.c="+v1.c+"  v2.c="+v2.c);
      v1=new Value(27);
      prt("v1.c="+v1.c+"  v2.c="+v2.c);
      v2=new Value(15);
      prt("v1.c="+v1.c+"  v2.c="+v2.c);
    }   public static void main(String[] args){
    Count ct=new Count();
   
    prt("ct.c="+ct.v.c);
    prt("v1.c="+v1.c+"  v2.c="+v2.c);
    v1.inc();
    prt("v1.c="+v1.c+"  v2.c="+v2.c);
    prt("ct.c="+ct.v.c);
  }
}
class Value{
  static int c=1;
  Value(){
    c=15;
  }
  Value(int i){
    c=i;
  }
  static void inc(){
    c++;
  }
}

解决方案 »

  1.   

    是这样的,/*
     * 创建日期 2005-8-1
     *
     * TODO 要更改此生成的文件的模板,请转至
     * 窗口 - 首选项 - Java - 代码样式 - 代码模板
     *//**
     * @author Administrator
     * 
     * TODO 要更改此生成的类型注释的模板,请转至 窗口 - 首选项 - Java - 代码样式 - 代码模板
     */
    public class Count {
    public static void prt(String s) {
    System.out.println(s);
    } Value v = new Value(10); static Value v1, v2; static {
    prt("v1.c=" + v1.c + "  v2.c=" + v2.c);
    v1 = new Value(27);
    prt("v1.c=" + v1.c + "  v2.c=" + v2.c);
    v2 = new Value(15);
    prt("v1.c=" + v1.c + "  v2.c=" + v2.c);
    } public static void main(String[] args) {
    Count ct = new Count(); prt("ct.c=" + ct.v.c);
    prt("v1.c=" + v1.c + "  v2.c=" + v2.c);
    v1.inc();
    prt("v1.c=" + v1.c + "  v2.c=" + v2.c);
    prt("ct.c=" + ct.v.c);
    }
    }class Value {
    static int c = 0; Value() {
    c = 15;
    } Value(int i) {
    c = i;
    } static void inc() {
    c++;
    }
    }
      

  2.   

    引用类的静态--->本类静态静态---->本类其它我也不是很懂呢!!大家谈谈啦!!
      

  3.   

    v1.c=1  v2.c=1
    v1.c=27  v2.c=27
    v1.c=15  v2.c=15
    ct.c=10
    v1.c=10  v2.c=10
    v1.c=11  v2.c=11
    ct.c=11看了这个你就明白了 !
    The order of initialization is statics first, if they haven’t already been initialized by a previous object creation, and then the non-static objects. You can see the evidence of this in the output. 
    It’s helpful to summarize the process of creating an object. Consider a class called Dog: The first time an object of type Dog is created (the constructor is actually a static method), or the first time a static method or static field of class Dog is accessed, the Java interpreter must locate Dog.class, which it does by searching through the classpath. As Dog.class is loaded (creating a Class object, which you’ll learn about later), all of its static initializers are run. Thus, static initialization takes place only once, as the Class object is loaded for the first time. When you create a new Dog( ), the construction process for a Dog object first allocates enough storage for a Dog object on the heap.This storage is wiped to zero, automatically setting all the primitives in that Dog object to their default values (zero for numbers and the equivalent for boolean and char) and the references to null. Any initializations that occur at the point of field definition are executed. Feedback 
    Constructors are executed. As you shall see in Chapter 6, this might actually involve a fair amount of activity, especially when inheritance is involved. Feedback
      

  4.   

    v1.c=1  v2.c=1
    v1.c=27  v2.c=27
    v1.c=15  v2.c=15
    ct.c=10
    v1.c=10  v2.c=10
    v1.c=11  v2.c=11
    ct.c=11