This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

passing primitive variables KB(chap3)

 
Syed Naimathullah
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How program flow is going on please explain in detail

import java.awt.Dimension;
class ReferenceTest1
{
public static void main(String[] args)
{
Dimension d=new Dimension(5,10);
ReferenceTest1 rt=new ReferenceTest1();
System.out.println("Before modify() d.height="+d.height);
rt.modify(d);
System.out.println("After modify() d.height="+d.height);
}
void modify(Dimension dim)
{
dim.height=dim.height+1;
System.out.println("dim="+dim.height);

}
}
 
Freddy Wong
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Everything in Java is pass-by-value.

For primitives, you pass a copy of the actual value.
For references to objects, you pass a copy of the reference.

The example given to you is for reference to object.

Take a look at this link and try to understand how pass-by-value works in Java.

http://www.javaranch.com/campfire/StoryPassBy.jsp
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use Code Tags when posting code. Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic