• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

question about null object

 
Anu Bhagat
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

It may sound stupid question, but I must ask
In the code below the object reference d2 is cerated using null d1. so what this object is like? is it also null?
also with line Dog d1 = null, do we get an object on the heap?



Thanks in advance.

Anu
 
Campbell Ritchie
Sheriff
Pie
Posts: 49865
71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried it? Will that code actually compile?
 
jittu goud
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


you are using the non default Dog Constructor ..where is the implementaion of it ?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@jittu goud: One way folks try to help beginners is to get them to think things through for themselves rather than just handing the answer to them!
 
Anu Bhagat
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the complete code is like this


My question is- is d2 null? ( i think it should be - but not sure )do we get any object on heap? do null onject live on the heap?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you think it would be null? What, precisely, is happening when you execute the Dog(Dog d) constructor? Is is still instantiating a Dog?
 
jittu goud
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote:@jittu goud: One way folks try to help beginners is to get them to think things through for themselves rather than just handing the answer to them!


oops my bad ....on the other side...iam a beginner myself..... :shock:
 
jittu goud
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
anu Its not null...

Dog d2 = new Dog(d1) ...

i think the "new Dog(d1)" will create a new object with null value
...but d2 will store the object reference ..rather than the actual object

in this case you should get the value of d2 as Dog@3e25a5

but still the d2.d will be null
 
jittu goud
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

i made a few changes....to your code
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic