Created
October 21, 2017 15:06
-
-
Save javamultiplex/50a05c58bdcd71c7ef13544d761ab012 to your computer and use it in GitHub Desktop.
Example of CloneNotSupportedException present in java.lang package
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
package com.javamultiplex.java.lang.exceptions; | |
/** | |
* @author Rohit Agarwal | |
* @version 1.0 | |
* @category java.lang/Exception | |
* @since JDK 1.0 | |
*/ | |
class Employee { | |
private String name; | |
public Employee(String name) { | |
super(); | |
this.name = name; | |
} | |
@Override | |
public String toString() { | |
return "Employee[Name= " + name + "]"; | |
} | |
@Override | |
protected Object clone() throws CloneNotSupportedException { | |
return super.clone(); | |
} | |
} | |
public class CloneNotSupportedExceptionDemo { | |
public static void main(String[] args) { | |
Employee emp1 = new Employee("Rohit"); | |
System.out.println(emp1); | |
try { | |
/* | |
* CloneNotSupportedException will be thrown because Employee class | |
* not implemented Cloneable interface. | |
*/ | |
Employee emp2 = (Employee) emp1.clone(); | |
System.out.println(emp2); | |
} catch (CloneNotSupportedException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment