File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question about variables

 
Ameem Shaik
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I need clarification about why these two scenarios produce different type of results.
When you have something like:


y=3, not 7.

However, when you have something like this:


a.size =20, not 10.

What causes this difference? I'm guessing it has to do something with the difference in primitive variables and object reference variables, but I'm not entirely sure. I'm new to both Java and programming in general, so can someone explain this to me? Thanks.

 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

Read this and then this and I guarantee you will understand perfectly!
 
Jim Hoglund
Ranch Hand
Posts: 525
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ameem : Welcome to the ranch. With just a quick look you'll see
that you created just one object with new, but with two reference
variables for it. So you can use either variable to change the object's
state or to look at it.

Jim ... ...
 
Ameem Shaik
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you both for the help! It is now clear to me.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic