Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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();
- }
- }
- }
Add Comment
Please, Sign In to add comment