-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrganization.java
More file actions
59 lines (49 loc) · 1.81 KB
/
Organization.java
File metadata and controls
59 lines (49 loc) · 1.81 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
class Organization implements Cloneable {
private String organizationCode;
private String organizationName;
private String organizationAddress;
// Constructor
public Organization(String organizationCode, String organizationName, String organizationAddress) {
this.organizationCode = organizationCode;
this.organizationName = organizationName;
this.organizationAddress = organizationAddress;
}
// Getter methods
public String getOrganizationCode() {
return organizationCode;
}
public String getOrganizationName() {
return organizationName;
}
public String getOrganizationAddress() {
return organizationAddress;
}
// Method to print object details
public void printDetails() {
System.out.println("Organization Code: " + organizationCode);
System.out.println("Organization Name: " + organizationName);
System.out.println("Organization Address: " + organizationAddress);
}
// Overriding clone method to support cloning
@Override
protected Object clone() throws CloneNotSupportedException {
return super.clone();
}
}
public class Main {
public static void main(String[] args) {
// Creating an organization object
Organization org1 = new Organization("ABC123", "Example Corp", "123 Main St");
try {
// Cloning the organization object
Organization org2 = (Organization) org1.clone();
// Printing details of both objects
System.out.println("Details of original organization:");
org1.printDetails();
System.out.println("\nDetails of cloned organization:");
org2.printDetails();
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
}
}