public class Customer {

private int custId;
private String user;
private String password;
private String name;
private String title;
private String email;

private boolean checkin=false;

public Customer(){}
public int getCustid(){return custId;}
public String getUser(){return user;}
public String getPassword(){return password;}
public String getName(){return name;}
public String getTitle(){return title;}
public String getEmail(){return email;}
public boolean getCheckin(){return this.checkin;}

}
为什么public boolean getCheckin(){return this.checkin;}要加上this,其它几个就不用this呢?谢谢!

解决方案 »

  1.   


    public class Customer { private int custId; private String user; private String password; private String name; private String title; private String email; private boolean checkin = false; public Customer() { } public int getCustid() {
    return this.custId;
    } public String getUser() {
    return this.user;
    } public String getPassword() {
    return this.password;
    } public String getName() {
    return this.name;
    } public String getTitle() {
    return this.title;
    } public String getEmail() {
    return this.email;
    } public boolean getCheckin() {
    return this.checkin;
    }}
      

  2.   

    加不加都行,在类内部,只要没有和成员变量重名的临时变量,都可以不加 this,
    下面就得加! 
    public Customer(boolean checkin){ 
        this.checkin = checkin;
    } 我一般都加上this  因为我比较懒! 有的变量名实在是太长! this.帮助完成代码! 
      

  3.   

    this就是表示调用自己的变量或方法。
    还有一种用法,当你用开发工具开发的时候,不记得方法名的时候 通过调用this.**来提示
    public class Customer {
       private String name;
       
       public void setName(String name){
           this.name = name;//这时候 这两个name 代表不同的变量  前面的那个name就代表成员变量name,后面的就传
                                //进来的那个name; 
       }
    }