第一个程序Method t = new Method();
==>Method()
  { 
    this("dfasdfasffs",47);      height = i; <--- i是成员变量
    
  }Method(String s, int i)
  {
   this.s = s;
   this.i = i;
    i = 98; <--- 改变的是局部变量i,不是成员变量i  System.out.println("this sucess");  
  } 
s-->"dfasdfasffs"
i-->47
height --> 47
第二个程序Method t = new Method();
===> Method()
  { 
    this("dfasdfasffs",47);
    height = k;
    
  }s--->"dfasdfasffs"
i--->47
k=98
height --> 98 Method(String s, int i)
  {
   this.s = s;
   this.k = i;
    k = 98; <--- k是成员变量
  System.out.println("this sucess");  
  } 

解决方案 »

  1.   

    怎么判断局部变量i,不是成员变量i?而k却是成员变量呢?
    这两个变量实质性还是相同的哪!!!!!!
      

  2.   

    因为你的局部变量i和成员变量i重名,所以导致系统在同时出现i的时候不知道你所指的具体是哪一个。而用k的时候缺不通,系统知道k和i的区别。
      

  3.   

    如果局部变量和成员变量重名,那么局部的有限度高,
    比如常见的class A {
      private int x;
      public int setX(int x) { //参数,局部
        this.x //成员变量
    = x; //局部
      }
    }