.关于以下程序代码的说明正确的是(   D   

1class  HasStatic{

2    private  static  int  x=100

3    public  static  void  main(String  args[  ]){

4        HasStatic  hs1=new  HasStatic(  );

5        hs1.x++;

6        HasStatic  hs2=new  HasStatic(  );

7        hs2.x++;

8        hs1=new  HasStatic( );

9        hs1.x++;

10       HasStatic.x- -;

11       System.out.println(x=+x);

12    }

13 }

A 5行不能通过编译,因为引用了私有静态变量

B 10行不能通过编译,因为x是私有静态变量

C、程序通过编译,输出结果为:x=103

D、程序通过编译,输出结果为:x=102


该题中   静态变量X在方法运行前已经被分配好内存了  然后实例化之后他们调用的还是之前分配好内存的那个X  为此我专门又添加了两句话

public class HasStatic {
private static int x=100;
public static void main(String[] args) {

HasStatic hs1 = new HasStatic();


HasStatic hs2=new HasStatic();
System.out.println(hs1==hs2);
System.out.println(hs1.x==hs2.x);
hs1.x++;
System.out.println(hs1.x==hs2.x);
hs2.x++;
hs1=new HasStatic();
hs1.x++;
System.out.println(hs1.x==hs2.x);
HasStatic.x--;
System.out.println(hs1.x==hs2.x);
System.out.println("x="+x);
}
}

这里输出的是   

false

true

true
true
true
x=102

==的作用作用于对象来说是表示两个对象的地址一致不一致 而此时可以看出两个对象的地址是不一致的 但是他们调用的X的地址却又是一致的 (他们修改的是同一个X的值)