-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReferenceVariables1.java
More file actions
12 lines (10 loc) · 962 Bytes
/
Copy pathReferenceVariables1.java
File metadata and controls
12 lines (10 loc) · 962 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
String myString = new String("hello"); // Sets myString to point to a new String object instance that
// contains "hello".
String myString1 = "goodbye"; // Special case of String that does the same as the new keyword.
// This only works for Strings and the Number classes (Unit 12).
// Now we have two instances of the object String, one containing
// "hello" and one containing "goodbye".
String myString1 = myString; // myString1 now points to the same instance of a String object
// containing "hello" that myString points to. The "goodbye"
// instance is no longer pointed to by a reference variable so it
// is deleted from memory.