第一次打印的是你申明int i=4,j=5;时的值是4第二次打印是你secondMethod(int i){传入的参数是 7我也晕。

解决方案 »

  1.   

    你这只是定义类,要用的话可以在类一下写一个main方法,如下:
    public static void main(String[] args)
    {
    System.out.println(i);
    }
      

  2.   

    C:\java\ScopeExample.java:17: non-static variable i cannot be referenced from a static context
           System.out.println(i);
                              ^
    1 error不行,我做过的
      

  3.   

    main() 是静态方法,不能调 用I(静态方法只能调 用静态成员)
    把I换成static 的就行了
      

  4.   

    改了编译通过了,但是执行没有任何效果
    两个this.i分别为多少啊?
      

  5.   

    不用把i写成static ,
    由于i属于实例变量,所以只有类实例化为对象它才存在,所以main()应该写为:
    public static void main(String[] args)
      {
       ScopeExample object=new ScopeExample();
       System.out.println(object.i);
            }
      

  6.   

    如果要看两个this.i的值,main()写为:
    public static void main(String[] args)
      {
       ScopeExample object=new ScopeExample();
       System.out.println(object.i);
       object.firstMethod();
       System.out.println("in firstMethod ,this.i="+object.i);
       object.secondMethod(1);//这个参数1可以自己选择
       System.out.println("in secondMethod ,this.i="+object.i);
        }
      

  7.   

    public class ScopeExample{
     private int i=1;
     
     public  void firstMethod(){
      int i=4,j=5;
      this.i=i+j;
      int l=this.i;
      System.out.println(l);
      secondMethod(7);
      }
      public  void secondMethod(int i){
      int j=8;
      this.i=i+j;
      int l=this.i;
      System.out.println(l);
      }
    public static void main(String args[]){
    ScopeExample s=new ScopeExample();
    s.firstMethod();

    }
    }
    //不知道这样可不可以
      

  8.   

    我明白了,你的意思是第2个方法的输入参数是当前的i值,那就这样写:
    public static void main(String[] args)
      {
       ScopeExample object=new ScopeExample();
       System.out.println(object.i);
       object.firstMethod();
       System.out.println("in firstMethod ,this.i="+object.i);
       object.secondMethod(object.i);//传入你要的参数
       System.out.println("in secondMethod ,this.i="+object.i);
        }
      

  9.   

    哦,我才看到你是把7传给了第2个方法,那么main()写为:
    public static void main(String[] args)
      {
       ScopeExample object=new ScopeExample();
       System.out.println(object.i);
       object.firstMethod();
       System.out.println("in firstMethod ,this.i="+object.i);
       object.secondMethod(7);//类似你第1个方法的调用
       System.out.println("in secondMethod ,this.i="+object.i);
        }