Last active
August 29, 2015 14:06
-
-
Save MykolaBova/330075741ffdf05fd836 to your computer and use it in GitHub Desktop.
ClonePerson
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ClonePerson { | |
private String name; | |
public ClonePerson(String name) { | |
this.name = name; | |
} | |
public String getName() { | |
return name; | |
} | |
public static void main(String[] args) { | |
ClonePerson p = new ClonePerson("Sam"); | |
try { | |
// Person class doesn't implement Cloneable but tries to get clone. It fails | |
// with CloneNotSupportedException | |
ClonePerson pClone = (ClonePerson) p.clone(); | |
System.out.println(pClone.getName()); | |
} catch (CloneNotSupportedException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment