-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObjectReferencing.java
More file actions
33 lines (27 loc) · 920 Bytes
/
ObjectReferencing.java
File metadata and controls
33 lines (27 loc) · 920 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
import java.util.Date; // use java Date object
/**
* Tutorial program testing the implications
* when variables are created as REFERENCES
* and not PRIMITIVE types
* @see java.util.Date
*/
public class ObjectReferencing {
public static void main(String[] args) {
Date d1 = new Date(300000000L);
System.out.println("\nDate in main 1: "+ d1);
changeDate1(d1);
System.out.println("\nDate in main 2: "+ d1);
changeDate2(d1);
System.out.println("\nDate in main 3: "+ d1);
}
public static void changeDate1(Date d1) {
System.out.println("Date in changeDate1 1: "+ d1);
d1.setTime(800000000L); // input object itself is altered
System.out.println("Date in changeDate1 2: "+ d1);
}
public static void changeDate2(Date d1) {
System.out.println("Date in changeDate2 1: "+ d1);
d1 = new Date(900000000L); // creates new object
System.out.println("Date in changeDate2 2: "+ d1);
}
}