Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App
Next Article:
CompoundName clone() method in Java with Examples
Next article icon

CloneNotSupportedException in Java with Examples

Last Updated : 24 Sep, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report

CloneNotSupportedException is thrown to show that the clone method in class Object has been called to clone an object, but that the object's class does not implement the Cloneable interface.

Hierarchy:

Those applications which override the clone method can also throw this type of exception to indicate that an object couldn't or shouldn't be cloned.

Syntax:

public class CloneNotSupportedException extends Exception

Example of CloneNotSupportedException :

Java
// Java program to demonstrate CloneNotSupportedException  class TeamPlayer {      private String name;      public TeamPlayer(String name)     {         super();         this.name = name;     }      @Override public String toString()     {         return "TeamPlayer[Name= " + name + "]";     }      @Override     protected Object clone()         throws CloneNotSupportedException     {         return super.clone();     } }  public class CloneNotSupportedExceptionDemo {      public static void main(String[] args)     {          // creating instance of class TeamPlayer          TeamPlayer t1 = new TeamPlayer("Piyush");         System.out.println(t1);          // using try catch block         try {                           // CloneNotSupportedException will be thrown              // because TeamPlayer class not implemented              // Cloneable interface.                           TeamPlayer t2 = (TeamPlayer)t1.clone();             System.out.println(t2);         }          catch (CloneNotSupportedException a) {             a.printStackTrace();         }     } } 

Output : 


Next Article
CompoundName clone() method in Java with Examples
author
piyushkr2022
Improve
Article Tags :
  • Java
  • Java-Exceptions
Practice Tags :
  • Java

Similar Reads

  • java.net.BindException in Java with Examples
    The java.net.BindException is an exception that is thrown when there is an error caused in binding when an application tries to bind a socket to a local address and port. Mostly, this may occur due to 2 reasons, either the port is already in use(due to another application) or the address requested j
    2 min read
  • CompositeName clone() method in Java with Examples
    The clone() method of a javax.naming.CompositeName class is used to return a copy of this composite name object.If you made any changes to the components of this original composite name won't affect the new copy of CompositeName object and vice versa. Syntax: public Object clone() Parameters: This m
    2 min read
  • DateFormat clone() method in Java with Examples
    The clone() Method of DateFormat class is used to create a copy of this DateFormat. It creates another copy of this DateFormat. Syntax: public Object clone() Parameters: The method does not take any parameters. Return Value: The method returns a copy of the DateFormat. Below programs illustrate the
    1 min read
  • Date clone() method in Java with Examples
    The clone() method of Date class in Java returns the duplicate of the passed Date object. This duplicate is just a shallow copy of the given Date object.Syntax: public Object clone() Parameters: The method does not accept any parameters.Return Value: The method returns a clone of the object.Below pr
    2 min read
  • CompoundName clone() method in Java with Examples
    The clone() method of a javax.naming.CompoundName class is used to return a copy of this compound name object. If you made any changes to the components of this original compound name won't affect the new copy of the CompoundName object and vice versa. The clone and this compound name share the same
    2 min read
  • Calendar clone() Method in Java with Examples
    The clear() method in Calendar class is used to clone a calendar object. It basically creates a shallow copy of this object. Syntax: public Object clone() Parameters: The method does not take any parameters. Return Value: The method does not return any value. Below programs illustrate the working of
    2 min read
  • Collection add() Method in Java with Examples
    The add(E element) of java.util.Collection interface is used to add the element 'element' to this collection. This method returns a boolean value depicting the successfulness of the operation. If the element was added, it returns true, else it returns false. Syntax: Collection.add(E element) Paramet
    4 min read
  • Collections copy() method in Java with Examples
    The copy() method of java.util.Collections class is used to copy all of the elements from one list into another. After the operation, the index of each copied element in the destination list will be identical to its index in the source list. The destination list must be at least as long as the sourc
    3 min read
  • java.lang.ArrayIndexOutOfBoundsExcepiton in Java with Examples
    The java.lang.ArrayIndexOutOfBoundsException is a runtime exception and thrown only at the execution state of the program. Java compiler never checks for this error during compilation. The java.lang.ArrayIndexOutOfBoundsException is one of the most common exceptions in java. It occurs when the progr
    2 min read
  • Arrays.copyOfRange() in Java with Examples
    Arrays copyOfRange() method is used to create a new array by copying a specified range of elements from an existing array. It provides a way to copy a subset of elements between two indices by creating a new array of the same type. Below is a simple example that uses Arrays.copyOfRange() method to c
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences