testclone1.java
来自「Java面向对象编程(随书配套源代码) 阐述了面向对象编程的思想」· Java 代码 · 共 30 行
JAVA
30 行
package chapter8;
class TestClone1 implements Cloneable
{
int a;
double b;
TestClone1 cloneTest()
{
try
{
return (TestClone1) super.clone();
}
catch(CloneNotSupportedException e)
{
System.out.println("Cloning not allowed.");
return this;
}
}
public static void main(String args[])
{
TestClone x1 = new TestClone1();
TestClone1 x2;
x1.a = 10;
x1.b = 20.98;
x2 = x1.cloneTest();
System.out.println("x1: " + x1.a + " " + x1.b);
System.out.println("x2: " + x2.a + " " + x2.b);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?