这两个设置方法的功能是否相同?

时间:2018-08-30 00:45:50

标签: java

一个二传手使用“ this”,一个不使用“ this”,但是它们的功能相同吗?

public void setHoursWorked(int hours) { 
    if (hours > 0) 
        hoursWorked = hours;
        else { 
            System.out.println("Error: HoursWorked Cannot be Smaller than Zero");
            System.out.println("Error: HoursWorked is not updated");
        }
          }


public void setHoursWorked (int hoursWorked) { 
    if (hoursWorked > 0) {
        this.hoursWorked = hoursWorked
    }
}

0 个答案:

没有答案