封装
1.隐藏类内部实现细节(封装)
2.步骤:
a.将属性私有化(private)
b.提供getter/setter 方法(getXxx(),setXxx())
c.在getter/setter中加入控制语句
3.this 关键词:
this:表示当前对象
调用属性:this.属性名
调用方法:this.方法名();
this():表示调用构造函数。
注意:this();必需写在构造函数的第一行。
public class Excelle {
private String type;
private String id;
public Excelle(){
}
public Excelle(String id,String type){
this.type=type;
this.id=id;
}
public String getType(){
return type;
}
public String getId(){
return id;
}
}
public class Regal {
private String type;
private String id;
public Regal(){
}
public Regal(String id,String type){
this.type=type;
this.id=id;
}
public String getType(){
return type;
}
public String getId(){
return id;
}
}