Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

object cloning in java

/*
The object cloning is a way to create exact copy of an object. 
The clone() method of Object class is used to clone an object.
*/

class Student18 implements Cloneable{  
int rollno;  
String name;  
  
Student18(int rollno,String name){  
this.rollno=rollno;  
this.name=name;  
}  
  
public Object clone()throws CloneNotSupportedException{  
return super.clone();  
}  
  
public static void main(String args[]){  
try{  
Student18 s1=new Student18(101,"amit");  
  
Student18 s2=(Student18)s1.clone();  
  
System.out.println(s1.rollno+" "+s1.name);  
System.out.println(s2.rollno+" "+s2.name);  
  
}catch(CloneNotSupportedException c){}  
  
}  
} 

/*
Output:101 amit
       101 amit
*/       
Comment

PREVIOUS NEXT
Code Example
Java :: Iterator to list (Java) 
Java :: set spring context 
Java :: how to change color of drawable in android 
Java :: 2d array java 
Java :: pre increment and post increments 
Java :: calculate number of years months and days between two dates in java 
Java :: java first character string number 
Java :: download File java from website 
Java :: How to get the nth Fibonacci number code in Java using recursion 
Java :: rock paper scissor in java 
Java :: chenge font android studio 
Java :: H2 enabling remote database creation first 
Java :: spring boot get request body 
Java :: import java.lang.Math.*; 
Java :: how to convert a string to char in java 
Java :: add a value to a list java in java hashmap 
Java :: Date(Long) to integer and back 
Java :: float java 
Java :: java how to create an array with existing objects 
Java :: Java ArrayList Class of Collections 
Java :: vscode code formatter cannot format 
Java :: how to create an array without knowing the size java 
Java :: linked list java 
Java :: android search in webview 
Java :: java lambda expressions 
Java :: char array to string in java 
Java :: java create arraylist with size 
Java :: abstract method declaration 
Java :: select list of values from db java 
Java :: Implementation of LinkedHashMap Class in Java map 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =