-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcloningProblem.java
More file actions
39 lines (35 loc) · 1.16 KB
/
cloningProblem.java
File metadata and controls
39 lines (35 loc) · 1.16 KB
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
35
36
37
38
39
/* Another Simple Deep Clone Problem that is simple to understand than the previous clone problem
* This one is far simple with two objects to Understand
* @author: Pradumn Patel
*/
class Student implements Cloneable{
String stname;
Institute obj;
public Object clone() throws CloneNotSupportedException{
return super.clone();
}
}
class Institute implements Cloneable{
Student st;
String inname;
String idAdd;
public Object clone() throws CloneNotSupportedException{
Institute inst=(Institute)super.clone();
inst.st=(Student)st.clone();
return st;
}
}
public class cloningProblem {
public static void main(String[] args)throws CloneNotSupportedException{
System.out.println("Original Object Student");
Student st1=new Student();
st1.stname="Hello";
Student st2 = (Student)st1.clone();
Institute inst=new Institute();
Student st3= (Student) inst.st.clone();
st2.stname="Wow New Name";
st3.stname="NONOW";
System.out.println("New object created: "+st2.stname);
System.out.println("New deep object: "+st3.stname);
}
}