Java复制构造函数
Java没有显式的构造函数" title="复制构造函数">复制构造函数,但是我们可以模仿行为。请参阅以下示例-
示例
public class Tester {
private String message;
public Tester(String message){
this.message = message;
}
public Tester(Tester tester){
this.message = tester.message;
}
public String getMessage(){
return message ;
}
public void setMessage(String message){
this.message = message;
}
public static void main(String[] args) {
Tester tester = new Tester("Welcome");
System.out.println(tester.getMessage());
Tester tester1 = new Tester(tester);
System.out.println(tester1.getMessage());
}
}
以上是 Java复制构造函数 的全部内容, 来源链接: utcz.com/z/327052.html