class Class1
    {
        student stu = new student();
        static void Main()
        { 
            
        }
    }
问题:
 在Main方法中不能访问 stu对象吗?

解决方案 »

  1.   

    静态方法不能访问非静态成员,
    static student stu = new student()
    就可以了
      

  2.   

    静态的成员不能访问非静态成员,非静态成员是能够访问的,
    例如:
    class Test{
      public static void A(){ //静态成员
         System.out.println("我是A方法");
          B()     //错误,静态成员不能访问非静态成员
          Test test = new Test();
          test.B();      //必须新new一个对象来调用非静态成员
       }
      public void B(){        //非静态成员
          System.out.println("我是B方法");
          A();     //非静态成员能直接调用上面静态成员
       }
    }//如果知道当我没说.....
      

  3.   

    static方法不能调用非static的变量
      

  4.   

    建设LZ去理解下static关键字,在Java中非静态方法不能访问非静态变量的
      

  5.   

    STATIC修饰的方法只能调用static方法和属性,试想如果可以,当我以类的形式调用Test.Main(当然main是系统调用的),由于我没有实例化Test对象,所以student st=new student();没有执行,你的STUDENT对象不存在,我调用啥啊