File tree Expand file tree Collapse file tree 7 files changed +167
-0
lines changed Expand file tree Collapse file tree 7 files changed +167
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2
+ <classpath >
3
+ <classpathentry kind =" src" path =" src" />
4
+ <classpathentry kind =" con" path =" org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7" />
5
+ <classpathentry kind =" output" path =" bin" />
6
+ </classpath >
Original file line number Diff line number Diff line change
1
+ /bin /
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2
+ <projectDescription >
3
+ <name >CCVT_Code_Distribute</name >
4
+ <comment ></comment >
5
+ <projects >
6
+ </projects >
7
+ <buildSpec >
8
+ <buildCommand >
9
+ <name >org.eclipse.jdt.core.javabuilder</name >
10
+ <arguments >
11
+ </arguments >
12
+ </buildCommand >
13
+ </buildSpec >
14
+ <natures >
15
+ <nature >org.eclipse.jdt.core.javanature</nature >
16
+ </natures >
17
+ </projectDescription >
Original file line number Diff line number Diff line change
1
+ eclipse.preferences.version =1
2
+ org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode =enabled
3
+ org.eclipse.jdt.core.compiler.codegen.targetPlatform =1.7
4
+ org.eclipse.jdt.core.compiler.codegen.unusedLocal =preserve
5
+ org.eclipse.jdt.core.compiler.compliance =1.7
6
+ org.eclipse.jdt.core.compiler.debug.lineNumber =generate
7
+ org.eclipse.jdt.core.compiler.debug.localVariable =generate
8
+ org.eclipse.jdt.core.compiler.debug.sourceFile =generate
9
+ org.eclipse.jdt.core.compiler.problem.assertIdentifier =error
10
+ org.eclipse.jdt.core.compiler.problem.enumIdentifier =error
11
+ org.eclipse.jdt.core.compiler.source =1.7
Original file line number Diff line number Diff line change
1
+ package com .rt .cloning ;
2
+
3
+ public class Department implements Cloneable {
4
+
5
+ private int did ;
6
+ private String dname ;
7
+ public int getDid () {
8
+ return did ;
9
+ }
10
+ public void setDid (int did ) {
11
+ this .did = did ;
12
+ }
13
+ public String getDname () {
14
+ return dname ;
15
+ }
16
+ public void setDname (String dname ) {
17
+ this .dname = dname ;
18
+ }
19
+ public Department (int did , String dname ) {
20
+ super ();
21
+ this .did = did ;
22
+ this .dname = dname ;
23
+ }
24
+ public Department (Department dep ) {
25
+ // TODO Auto-generated constructor stub
26
+ this .did =dep .did ;
27
+ this .dname =dep .dname ;
28
+
29
+ }
30
+
31
+ @ Override
32
+ protected Department clone () throws CloneNotSupportedException {
33
+ // TODO Auto-generated method stub
34
+ return (Department )super .clone ();
35
+ }
36
+
37
+
38
+ }
Original file line number Diff line number Diff line change
1
+ package com .rt .cloning ;
2
+
3
+ public class Employee implements Cloneable {
4
+
5
+ int eid ;
6
+ public Employee (int eid , String ename ) {
7
+ super ();
8
+ this .eid = eid ;
9
+ this .ename = ename ;
10
+ }
11
+ public int getEid () {
12
+ return eid ;
13
+ }
14
+ public void setEid (int eid ) {
15
+ this .eid = eid ;
16
+ }
17
+ public String getEname () {
18
+ return ename ;
19
+ }
20
+ public void setEname (String ename ) {
21
+ this .ename = ename ;
22
+ }
23
+ public Department getDep () {
24
+ return dep ;
25
+ }
26
+ public void setDep (Department dep ) {
27
+ this .dep = dep ;
28
+ }
29
+ String ename ;
30
+ Department dep ;
31
+ public Employee (int eid , String ename , Department dep ) {
32
+ super ();
33
+ this .eid = eid ;
34
+ this .ename = ename ;
35
+ this .dep = dep ;
36
+ }
37
+ public Employee (Employee e1 ) {
38
+ this .eid =e1 .eid ;
39
+ this .ename =e1 .ename ;
40
+ this .dep =new Department (e1 .dep );
41
+
42
+ // TODO Auto-generated constructor stub
43
+ }
44
+ @ Override
45
+ public String toString () {
46
+ // TODO Auto-generated method stub
47
+ return "Employee id: " +eid +" Employee Name: " +ename +" Dep Name:" +dep .getDname ()+" Dep Id:" +dep .getDid ();
48
+ }
49
+
50
+ @ Override
51
+ protected Employee clone () throws CloneNotSupportedException {
52
+ // TODO Auto-generated method stub
53
+ Employee temp =(Employee )super .clone ();
54
+ temp .setDep (this .getDep ().clone ());
55
+
56
+ // temp.dep=this.dep.clone();
57
+
58
+ return temp ;
59
+ }
60
+
61
+
62
+
63
+
64
+ }
Original file line number Diff line number Diff line change
1
+ package com .rt .cloning ;
2
+
3
+ public class TestClass {
4
+
5
+ /**
6
+ * @param args
7
+ * @throws CloneNotSupportedException
8
+ */
9
+ public static void main (String [] args ) throws CloneNotSupportedException {
10
+ // TODO Auto-generated method stub
11
+ Department d1 =new Department (7 , "HR" );
12
+ Employee e1 =new Employee (1 , "Ram" ,d1 );
13
+ Employee e2 = e1 .clone ();
14
+
15
+
16
+
17
+ System .out .println (e1 );
18
+ System .out .println (e2 );
19
+ e2 .setEid (3 );
20
+ e2 .setEname ("Shyam" );
21
+ e2 .getDep ().setDid (8 );
22
+ e2 .getDep ().setDname ("Acc" );
23
+ System .out .println (e1 );
24
+ System .out .println (e2 );
25
+
26
+ System .out .println (e1 instanceof Cloneable );
27
+
28
+ }
29
+
30
+ }
You can’t perform that action at this time.
0 commit comments