标签:name ide images 技术 stack 子类 block object类 lock
package com.clone; class Cat implements Cloneable{ private int age; private String name; public void setAge(int age) { this.age = age; } public int getAge() { return age; } public Cat(int age,String name) { this.age=age; this.name=name; } public String toString() { return "姓名:"+this.name+",年龄:"+this.age; } @Override protected Object clone() throws CloneNotSupportedException { // TODO Auto-generated method stub return super.clone(); } } public class TestClone { public static void main(String[] args) { Cat cat1=new Cat(20,"小白"); Cat cat2=null; try { cat2=(Cat)cat1.clone(); } catch (CloneNotSupportedException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println(cat1); System.out.println(cat2); cat1.setAge(30); System.out.println(cat1); System.out.println(cat2); System.out.println(cat1==cat2); } }
标签:name ide images 技术 stack 子类 block object类 lock
原文地址:http://www.cnblogs.com/mylove-huan/p/7239006.html