forked from hacker85/JavaLessons
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImutableLesson.java
More file actions
57 lines (49 loc) · 1.27 KB
/
Copy pathImutableLesson.java
File metadata and controls
57 lines (49 loc) · 1.27 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
56
57
package advanced;
import java.util.Date;
public class ImutableLesson {
public static void main(String[] args) {
Student student = new Student(18, "Max", new Date());
int i = student.getAge();
String s = student.getName();
Date d = student.getDate();
i = 1;
s = "Mike";
d.setTime(0);
System.out.println(student.getAge());
System.out.println(student.getName());
System.out.println(student.getDate());
// Student student1 = new MyStudent(18, "Max", new Date());
// System.out.println(student1.getDate());
}
}
final class Student {
private int age;
private String name;
private Date date;
public Student(int age, String name, Date date) {
this.age = age;
this.name = name;
this.date = date;
}
public int getAge() {
return age;
}
public String getName() {
return name;
}
public Date getDate() {
return (Date)date.clone();
}
}
//class MyStudent extends Student {
// public MyStudent(int age, String name, Date date) {
// super(age, name, date);
// }
//
// @Override
// public Date getDate() {
// Date date = new Date();
// date.setTime(0);
// return date;
// }
//}