⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testclone2.java

📁 Java面向对象编程(随书配套源代码) 阐述了面向对象编程的思想
💻 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 + -