就是指Employee当前这个实例,也就是 上面调用者的staff[i]

解决方案 »

  1.   

    this 有一个很好辨认的方法
    就是:他出现在哪个类(对象)中,你就把THIS换成那个类名(对象名)
    这样,是不是就很好理解了啊?
      

  2.   

    但是这个staff[i]是在上面那个EmployeeTest里定义的阿?
    我很菜唉~~
      

  3.   

    原代码如下:
    import java.util.*;public class EmployeeTest
    {  
       public static void main(String[] args)
       {  
          // fill the staff array with three Employee objects
          Employee[] staff = new Employee[3];      staff[0] = new Employee("Carl Cracker", 75000,
             1987, 12, 15);
          staff[1] = new Employee("Harry Hacker", 50000,
             1989, 10, 1);
          staff[2] = new Employee("Tony Tester", 40000,
             1990, 3, 15);      // raise everyone's salary by 5%
          for (int i = 0; i < staff.length; i++)
             staff[i].raiseSalary(5);      // print out information about all Employee objects
          for (int i = 0; i < staff.length; i++)
          {  
             Employee e = staff[i];
             System.out.println("name=" + e.getName()
                + ",salary=" + e.getSalary()
                + ",hireDay=" + e.getHireDay());
          }
       }
    }class Employee
    {  
       public Employee(String n, double s, 
          int year, int month, int day)
       {  
          name = n;
          salary = s;
          GregorianCalendar calendar
             = new GregorianCalendar(year, month - 1, day);
             // GregorianCalendar uses 0 for January
          hireDay = calendar.getTime();
       }   public String getName()
       {  
          return name;
       }   public double getSalary()
       {  
          return salary;
       }   public Date getHireDay()
       {  
          return (Date)hireDay.clone();
       }   public void raiseSalary(double byPercent)
       {  
          double raise =this. salary * byPercent / 100;
          this.salary += raise;
       }   private String name;
       private double salary;
       private Date hireDay;
    }
      

  4.   

    我说的但是你一个类总有一个实例的啊,
    class Employee {
       public void raiseSalary(double byPercent)
       {  
         //因为每个类的成员变量都不相同的,
         //我调用abc.raiseSalary方法,那么在这个方法内部就需要访问abc的所有信息
         //所以在这个raiseSalary方法中使用this,就等于abc了 this == abc
          double raise =this. salary * byPercent / 100; 
          this.salary += raise;//
       }}
      
       private String name;
       private double salary;
       private Date hireDay;
    }