怎样获取另一个类中封装的属性

来源:互联网 发布:四知太守后人 编辑:程序博客网 时间:2024/06/15 01:20
class Sql{
private String fromtime1 = "fromtime1****";    //声明出差开始时间
private String totime1 = "totime1*****";    //声明出差结束时间
private String place1 = "place1*****";    //声明出差地点
private String people1 = "people1*****";    //声明同行人员
private String cost = "cost*****";    //声明花费

public Sql(String fromtime1,String totime1,String place1,String people1,String cost){    //对用户名和密码定义构造方法并赋值
this.fromtime1 = fromtime1 ; 
this.totime1 = totime1 ; 
this.place1 = place1 ; 
this.people1 = people1 ; 
this.cost = cost ;
this.setFromtime1(fromtime1);
this.setTotime1(totime1);
this.setPlace1(place1);
this.setPeople1(people1);
this.setCost(cost);
}
public void setFromtime1(String t1){
fromtime1 = t1;
}
public void setTotime1(String t2){
totime1 = t2;
}
public void setPlace1(String p1){
place1 = p1;
}
public void setPeople1(String pe1){
people1 = pe1;
}
public void setCost(String c1){
cost = c1;
}

public String getFromtime1(){
return fromtime1;
}
public String getTotime1(){
return totime1;
}
public String getPlace1(){
return place1;
}
public String getPeople1(){
return people1;
}
public String getCost(){
return cost;
}
}
public class test2 {


public static void main(String[] args) {
// TODO 自动生成的方法存根

Sql sql =new Sql("出差开始时间", "出差结束时间", "出差地点", "同行人员", "花费");
System.out.println("出差信息:"+sql.getFromtime1()+",  "+sql.getTotime1()+",  "+sql.getPlace1()+",  "+sql.getPeople1()+",  "+sql.getCost());

}


}
0 0