📄 customer2.java
字号:
//Customer2.java
//定义构造方法实现对象初始化,验证拷贝构造方法
class Customer2{
String name, address, telephone;
/*Customer2(){ //无参数构造方法
this.name="";
this.address="";
this.telephone="";
}
*/
Customer2(String name,String address,String telephone){
this.name=name;
this.address=address;
this.telephone=telephone;
}
Customer2(Customer2 customer){ //拷贝构造方法
name=customer.name;
address=customer.address;
telephone=customer.telephone;
}
String getName(){
return name;
}
void setName(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){
//Customer2 customer0 = new Customer2();
Customer2 customer1 = new Customer2("Wang Ming","#188 Beijing Road","0571-23503545");
Customer2 customer2 = new Customer2(customer1); //验证拷贝构造方法
System.out.println("The name of first customer is " + customer1.getName());
System.out.println("The address of first customer is " + customer1.getAddress());
System.out.println("The telephone of first customer is " + customer1.getTelephone());
System.out.println("The name of second customer is " + customer2.getName());
System.out.println("The address of second customer is " + customer2.getAddress());
System.out.println("The telephone of second customer is " + customer2.getTelephone());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -