forked from ShivangiSingh17/Java-Jet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObjectClone().java
More file actions
34 lines (23 loc) · 773 Bytes
/
ObjectClone().java
File metadata and controls
34 lines (23 loc) · 773 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// simple example of object cloning:
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,"Parkhi_Alahawat");
Student18 s2=(Student18)s1.clone();
System.out.println(s1.rollno+" "+s1.name);
System.out.println(s2.rollno+" "+s2.name);
}catch(CloneNotSupportedException c){}
}
}
/*Output:101 Parkhi_Alahawat
101 Parkhi_Alahawat
*/