-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPerson.java
More file actions
40 lines (36 loc) · 704 Bytes
/
Copy pathPerson.java
File metadata and controls
40 lines (36 loc) · 704 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
31
32
33
34
35
36
37
38
39
40
public class Person {
private String name; //Instance variable
//Constructors
public Person() //Default
{
this.name = "no name yet";
}
public Person(String aName)
{
//call mutator - avoid duplicate error checking
this.setName(aName);
}
//Accessor
public String getName()
{
return this.name;
}
//Mutators
//Generally want to do error checking but can't
public void setName(String aName)
{
this.name = aName;
}
//other methods
public boolean equals(Person aPerson)
{
//must first make sure aPerson exits
//avoi null reference exceptions
return aPerson != null &&
this.name.equals(aPerson.getName());
}
public String toString()
{
return this.name;
}
}