This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Objects instance variables value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Objects instance variables value" Watch "Objects instance variables value" New topic
Author

Objects instance variables value

Akshay Reddy
Greenhorn

Joined: May 14, 2009
Posts: 21


what is the difference between line 2 and line 3,
how does the values of e1.count and e2.count read for line 2 and line3
(say)
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18113
    
  39

what is the difference between line 2 and line 3,


In line 2, you are declaring a reference, and initializing it to the same object that is referenced by another reference.

In line 3, you are declaring a reference, and initializing it to a new object.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Akshay Reddy
Greenhorn

Joined: May 14, 2009
Posts: 21
you mean in line 2 e1 and e2 refer to the same object and in line 3 e2 is refering to a different object ...
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Yes.

Your while loop body will never execute, btw.
Akshay Reddy
Greenhorn

Joined: May 14, 2009
Posts: 21
i am sorry x<4 .
 
 
subject: Objects instance variables value
 
Similar Threads
Can some one explain this to me. It Display Hello 4x and output is 24
Classes and Projects Chapter 2 of Head start JAVA pool puzzle
Would like help about this excercise in HFJ
The value is not what i expected
adding up variables