您的位置:首页 > 其它

构造方法实现对象初始化

2013-11-05 16:26 267 查看
class train4_5 {
String name,address,telephone;
train4_5(String name,String address, String telephone){
this.name=name;
this.address=address;
this.telephone=telephone;
}
train4_5(train4_5 tr){
name=tr.name;
address=tr.address;
telephone=tr.telephone;
}
String getName(){
return name;
}
void srtName(String name){
this.name=name;
}
String getAddress(){
return address;
}
void setAddress(String address){
this.address=address;
}
String getTelephone(){
return telephone;
}
void setTelephone(String telephone){
this.telephone=telephone;
}
public static void main(String[] args) {
train4_5 tr1=new train4_5("WangMing","#188,BeiJingRoad","010-75356815");
train4_5 tr=new train4_5(tr1);
System.out.println(tr1.getName());
System.out.println(tr1.getAddress());
System.out.println(tr1.getTelephone());
System.out.println(tr.getName());
System.out.println(tr.getAddress());
System.out.println(tr.getTelephone());
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐