What will happen when you compile and run the following code?public class MyClass
{
static int x;

public static void main(String args[])
{
x = 5;
MyClass m1 = new MyClass();
MyClass m2 = new MyClass();
MyClass m3 = new MyClass(); m1.x = 10;
m2.x = 20;
m3.x = 30; System.out.println(m1.x);
System.out.println(m2.x);
System.out.println(m3.x); }
}

解决方案 »

  1.   

    The static field x has become the class attribute which means it does not belong to the instance of the class.
      

  2.   

    30
    30
    30static 变量,所有实例共享一份!
      

  3.   

    运行结果是
    30 
    30 
    30 
    这是JAVA基础的一个知识点,比较重要的!
      

  4.   

    static   变量,所有实例共享一份!
      

  5.   

    应该是30,30,30
    所有实例都共享static变量的,跟全局变量差不多似的
      

  6.   

    static变量,跟静态变量一样...结果是:30,30,30...
      

  7.   

    如果去掉那个static 把下面那个x = 5;去掉...就是独享..变成了10   20   30
      

  8.   

    public class MyClass
    {
        int x;
        
        public static void main(String args[])
        {
            x = 5;//这一句不去掉,为什么会出错呢?这是什麽错误呢?
            MyClass m1 = new MyClass();
            MyClass m2 = new MyClass();
            MyClass m3 = new MyClass();        m1.x = 10;
            m2.x = 20;
            m3.x = 30;        System.out.println(m1.x);
            System.out.println(m2.x);
            System.out.println(m3.x);    }
    }
      

  9.   

    to tsuliuchao :静态方法里面不能使用非静态成员