forked from ShivangiSingh17/Java-Jet
- Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathObjectClone().java
34 lines (23 loc) · 773 Bytes
/
ObjectClone().java
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:
classStudent18implementsCloneable{
introllno;
Stringname;
Student18(introllno,Stringname){
this.rollno=rollno;
this.name=name;
}
publicObjectclone()throwsCloneNotSupportedException{
returnsuper.clone();
}
publicstaticvoidmain(Stringargs[]){
try{
Student18s1=newStudent18(101,"Parkhi_Alahawat");
Student18s2=(Student18)s1.clone();
System.out.println(s1.rollno+" "+s1.name);
System.out.println(s2.rollno+" "+s2.name);
}catch(CloneNotSupportedExceptionc){}
}
}
/*Output:101 Parkhi_Alahawat
101 Parkhi_Alahawat
*/