• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

String issue

 
Ranch Hand
Posts: 460
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,




Why s2 is not null, because s1 becomes null, s1 remains "Manish"?

I am very confused.

Can you help me?

 
Marshal
Posts: 8863
637
Mac OS X VI Editor BSD Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Think you have a dog, which has two laces which are secured on his neck/head (in your case it is object "Manish"). Now you cut one of the lace, what happens with other? It still on dog's neck. That's probably confusing.

s1 isn't an object, but rather a reference variable which refers to a string object "Manish". Now that you let s2 variable to refer to the same object, "Manish" now has two reference variables referencing to him. So, if you eliminate s1, s1 is no longer pointing to "Manish", but hey, s2 still does. Similarly as in an above example I crossed off.
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dana Ucaed wrote:Why s2 is not null, because s1 becomes null, s1 remains "Manish"?


You should definitely read this excellent article.
 
Ranch Hand
Posts: 51
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
s2 is not null because at this line

you made it refer to object . And with line

you made s1 refer to null in memory
 
reply
    Bookmark Topic Watch Topic
  • New Topic