📄 testclone2.java
字号:
package chapter8;
class TestClone2 implements Cloneable
{
int a;
double b;
public Object clone()
{
try
{
// 在对象内调用clone()方法
return super.clone();
}
catch(CloneNotSupportedException e)
{
System.out.println("Cloning not allowed.");
return this;
}
}
public static void main(String args[])
{
TestClone2 x1 = new TestClone2();
TestClone2 x2;
x1.a = 10;
x1.b = 20.98;
// 这里直接调用clone()方法
x2 = (TestClone2) x1.clone();
System.out.println("x1: " + x1.a + " " + x1.b);
System.out.println("x2: " + x2.a + " " + x2.b);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -