Nagashri Kadur

Greenhorn
+ Follow
since Dec 04, 2012
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Nagashri Kadur

Oh... OK. Guess there is way more to this than I thought. Thank you Henry ! Let me read up the difference... I really appreciate your guidance
11 years ago
When you pass by reference, the address gets passed. So, any changes made will be reflected. Is that right ?
11 years ago

Henry Wong wrote:

Nagashri Kadur wrote: public static void main(String[] args) {
String str1 = new String("This is a string");
str1 = "I thought this was immutable !! \n How \t did \t this \t happen ? ";
System.out.println("str1 = " + str1 );
}

The above mentioned code is compiling and is resulting in the following being displayed.
str1 = I thought this was immutable !!
How did this happen ?
If String is immutable how is this working ?



Can you tell us the difference between an object and a reference?

Henry



When you pass by reference, you pass the address. Am I correct ?
11 years ago
public static void main(String[] args) {
String str1 = new String("This is a string");
str1 = "I thought this was immutable !! \n How \t did \t this \t happen ? ";
System.out.println("str1 = " + str1 );
}

The above mentioned code is compiling and is resulting in the following being displayed.
str1 = I thought this was immutable !!
How did this happen ?
If String is immutable how is this working ?
11 years ago