-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPerson.java
61 lines (44 loc) · 917 Bytes
/
Person.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
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
60
61
public class Person {
private String fName;
private String lName;
private int age;
public void setFirstName (String fn) { //mutator, "setter"
fName = fn;
}
public void setLastName (String ln) {
lName = ln;
}
public void setAge(int a) {
if (a >= 0)
age = a;
}
public String getFirstName() {
return fName;
}
public String getLastName() {
return lName;
}
public int getAge() {
return age;
}
public String getName() {
return fName + ' ' + lName;
}
public String getNameLNF() {
return lName + ", " + fName;
}
public String toString() {
return fName + ' ' + lName + ", age: " + age;
}
}
class PersonTester {
public static void main(String args[]) {
Person p1 = new Person();
p1.setFirstName("Fred");
p1.setLastName("Flintstone");
p1.setAge(43000000);
Person p2 = p1;
p2.setFirstName("Wilma");
System.out.println(p1.toString());
}
}