Special Offer - Enroll Now and Get 2 Course at ₹25000/- Only Explore Now!

All Courses
Java Clone Object

Java Clone Object

April 30th, 2019

Java Clone Object:

Object Cloning in Java

Creating a copy of an object. Method clone() in Object class is used to clone an object. No need to write repetitive & lengthy codes and also its most efficient & easiest way for copying objects.


protected Object clone() throws CloneNotSupportedException


class Vehicle implements Cloneable {
int modelyear=0;
String modelname = “”;
Vehicle(String modelname , int modelyear){
public Object clone() throws CloneNotSupportedException {
return super.clone();
public static void main(String args[])  {
Vehicle v = new Vehicle();
Vehicle v1=(Vehicle)v.clone();
System.out.println(v. modelname +" "+ v. modelyear);
System.out.println(v1. modelname +" "+ v1. modelyear);
}catch(CloneNotSupportedException e){