aspose file tools*
The moose likes Beginning Java and the fly likes The value is not what i expected Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "The value is not what i expected" Watch "The value is not what i expected" New topic
Author

The value is not what i expected

Binar Guardinho
Greenhorn

Joined: Oct 19, 2010
Posts: 5


Why output is "30" ? Everytime it does , and value of e1.count is "0", it should print "2" in the end, can't understand how it works. Please someone to explain me. Thank You
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

e2 = e1 is just a distraction. Imagine that there is only one object. Will that help to understand the result ?


[My Blog]
All roads lead to JavaRanch
Binar Guardinho
Greenhorn

Joined: Oct 19, 2010
Posts: 5
Christophe Verré wrote:e2 = e1 is just a distraction. Imagine that there is only one object. Will that help to understand the result ?


Can't understand. I was tested before something like this

The result was 3, so e2 recive value of e1, result that e2.count should be "0" every time on the main example. Any idea?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Imagine your have two baskets where you put your cloths in. If you put the first basket into the second basket and put cloths in it, in which basket are the cloths ? If put the first basket in the second basket again (although it was already in there) and add some more cloths, in which basket are the cloths ?

What I'm trying to say (in a very confusing way ), is that e2 is always e1. The Echo() instance represented by "Echo e2 = new Echo();" will be discarded as soon as e2 = e1. Only e1 is alive. Everything happens in e1. e2 is e1. So e2.count = e2.count + 1; is actually e1.count = e1.count + 1;. System.out.println(e2.count); is actually System.out.println(e1.count);...
Binar Guardinho
Greenhorn

Joined: Oct 19, 2010
Posts: 5
Christophe Verré wrote:Imagine your have two baskets where you put your cloths in. If you put the first basket into the second basket and put cloths in it, in which basket are the cloths ? If put the first basket in the second basket again (although it was already in there) and add some more cloths, in which basket are the cloths ?

What I'm trying to say (in a very confusing way ), is that e2 is always e1. The Echo() instance represented by "Echo e2 = new Echo();" will be discarded as soon as e2 = e1. Only e1 is alive. Everything happens in e1. e2 is e1. So e2.count = e2.count + 1; is actually e1.count = e1.count + 1;. System.out.println(e2.count); is actually System.out.println(e1.count);...

Now it's clear . Thnx man
J Kim
Greenhorn

Joined: Apr 09, 2011
Posts: 2
2 baskets sample is very good!
Thank you very much Christophe Verré !
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: The value is not what i expected