Win a copy of Terraform in Action this week in the Cloud forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

object referencing

 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey evey one,
i have small doubt regarding a question :



in this code if we declare e2=null alone tats enough to make every object as null know?? so why here we are declaring e3 and e1 also as a null!!! there is no need of it know?
 
author
Posts: 23909
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please Quote Your Sources.

Thanks,
Henry
 
vijay umar
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1.


in this code if we declare e2=null alone tats enough to make every object as null know?? so why here we are declaring e3 and e1 also as a null!!! there is no need of it know?




this wat you said about
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
declaring e2=null doesn't change e1 or e3, they still reference instances of object. Only e2 reference is set to null

If code does correct things but doesn't make much sense - most likely this is an exam question
 
Henry Wong
author
Posts: 23909
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Quoting Your Sources does not mean to repeat your question. Please see the link for details.

Questions without sources will be deleted.

Henry
 
vijay umar
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this question is from kathy serra book..the master cd quiz question!!!


here i am confused about the statments like
i2.n=i3;
i3.n=i4;
i4.n=i2;


here i2.n means that n is a variable of i2 instance ...... So is i2.n and i2 are both same or what?

I am little confuse about which is refering to what and what is getting nulled here!!



 
Henry Wong
author
Posts: 23909
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

here i am confused about the statments like
i2.n=i3;
i3.n=i4;
i4.n=i2;


here i2.n means that n is a variable of i2 instance ...... So is i2.n and i2 are both same or what?



i2 is a reference variable. It points to an object -- and that object has in instance (or static, can't tell here) variable called n.

So... when you do this...

i2.n=i3;



You are deferencing the object referenced by i2 and setting the n instance variable to point to the same object that i3 is pointing to.

Henry
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

You are deferencing the object referenced by i2 and setting the n instance variable to point to the same object that i3 is pointing to.



The object referenced by i2 is unchanged or is it also pointing to i3. As per my understanding, i2.n now points to i3 and i2 is still pointing to the original object it was pointing too ? Please correct me if i am mistaken...
 
vijay umar
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So now can you explain that when any one of the object will be eligible for garbage collection ? is it after the line no. 11...
 
vijay umar
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
e3.e=e2;
e1.e=e3;
e2.e=e1;
e3=null;
e2=null;
e1=null;

then what is the order the execution follows here!!!

here e1,e2,e3 are all made null............... So when e2.e=e1 is used then then as at this point e2 referce to null.... then how can we use a null reference now.... shouldnt it give a NullPointerException at this point??
 
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

vijay umar wrote: So when e2.e=e1 is used then then as at this point e2 referce to null.... then how can we use a null reference now.... shouldnt it give a NullPointerException at this point??


Yes. A NullPointerException will be thrown.
And btw. in your example all objects are chained together like in a single linked list. Only if all the references are nulled you'll have objects eligible for the garbage collector.

cheers
Bob
 
vijay umar
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic