-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPerson.java
More file actions
48 lines (31 loc) · 1021 Bytes
/
Person.java
File metadata and controls
48 lines (31 loc) · 1021 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
41
42
43
44
45
46
47
public class Person {
private String name;
public Person(String name){
this.name =name;
}
// returns the person's name
public String getName(){
return name;
}
// changes the name property to the passed value
public void setName(String name){
this.name = name;
}
// prints a message to the console using the person's name
public void sayHello(){
System.out.println("Howdy " + this.name + ", Nice to see You!");
}
public static void main(String[] args) {
// Person person = new Person("Tom");
// person.setName("Dan");
// person.sayHello();
// System.out.println(person.getName());
Person person1 = new Person("Gunnar");
Person person2 = person1;
System.out.println(person1.getName());
System.out.println(person2.getName());
person2.setName("Graham");
System.out.println(person1.getName());
System.out.println(person2.getName());
}
}