Guest User

Untitled

a guest
Oct 22nd, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. package com.javamultiplex.java.lang.exceptions;
  2.  
  3. /**
  4. * @author Rohit Agarwal
  5. * @version 1.0
  6. * @category java.lang/Exception
  7. * @since JDK 1.0
  8. */
  9.  
  10. class Employee {
  11.  
  12. private String name;
  13.  
  14. public Employee(String name) {
  15. super();
  16. this.name = name;
  17. }
  18.  
  19. @Override
  20. public String toString() {
  21. return "Employee[Name= " + name + "]";
  22. }
  23.  
  24. @Override
  25. protected Object clone() throws CloneNotSupportedException {
  26. return super.clone();
  27. }
  28.  
  29. }
  30.  
  31. public class CloneNotSupportedExceptionDemo {
  32.  
  33. public static void main(String[] args) {
  34.  
  35. Employee emp1 = new Employee("Rohit");
  36. System.out.println(emp1);
  37. try {
  38. /*
  39. * CloneNotSupportedException will be thrown because Employee class
  40. * not implemented Cloneable interface.
  41. */
  42. Employee emp2 = (Employee) emp1.clone();
  43. System.out.println(emp2);
  44. } catch (CloneNotSupportedException e) {
  45. e.printStackTrace();
  46. }
  47.  
  48. }
  49.  
  50. }
Add Comment
Please, Sign In to add comment