Skip to content

Instantly share code, notes, and snippets.

@devDeejay
Created September 12, 2018 20:18
Show Gist options
  • Select an option

  • Save devDeejay/eb6af6511c1f9b7ad080729829b4b06d to your computer and use it in GitHub Desktop.

Select an option

Save devDeejay/eb6af6511c1f9b7ad080729829b4b06d to your computer and use it in GitHub Desktop.
public class StormTrooper implements Cloneable {
String color = "White";
String master = "Darth Vader";
StormTrooper() {
System.out.println("Welcome to the Dark Side");
}
@Override
protected Object clone() throws CloneNotSupportedException {
StormTrooper trooper = null;
try {
trooper = (StormTrooper) super.clone();
// New Object master will be the same as cloning object's Master
trooper.master = this.master;
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
return trooper;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment