-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHusband.java
More file actions
30 lines (24 loc) · 701 Bytes
/
Copy pathHusband.java
File metadata and controls
30 lines (24 loc) · 701 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
class Husband {
private String name;
private Wife wife;
public Husband(String name) {
this.name = name;
}
public void getMarried(Wife wife) {
this.wife = wife;
}
public String getSalutation() {
if (wife != null) {
return "Mr. and Mrs. " + name;
} else {
return "Mr. " + name;
}
}
public static void main(String[] args) {
Husband john = new Husband("John Smith");
Wife jane = new Wife("Jane Doe");
System.out.println(john.getSalutation()); // Should print "Mr. John Smith"
john.getMarried(jane);
System.out.println(john.getSalutation()); // Should print "Mr. and Mrs. John Smith"
}
}