forked from QAMINDS/java_selenium
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDog.java
More file actions
55 lines (44 loc) · 1.37 KB
/
Dog.java
File metadata and controls
55 lines (44 loc) · 1.37 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
package module1.java_basic;
public class Dog {
private String name;
private int age;
private int position;
Dog(String name, int age) {
this.name = name;
this.age = age;
this.position = 0;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public int getPosition() {return position;}
public void run(int distance) {
this.position += distance;
}
public String toString() {
return String.format("%s has %d years, position: %d", this.name, this.age, this.position);
}
public static void main(String[] args){
Dog dog = new Dog("Rex", 1);
dog.run(10);
assert dog.getPosition() == 10;
System.out.println(dog.toString());
modifyDog(dog);
System.out.println(String.format("ID outside modify method: %d", System.identityHashCode(dog)));
}
public static void modifyDog(Dog dog) {
System.out.println(String.format("ID before new assignment: %d", System.identityHashCode(dog)));
dog = new Dog("Max", 5);
assert dog.getName() == "Max";
System.out.println(String.format("ID after new assignment: %d", System.identityHashCode(dog)));
}
}