wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes passing primitive variables KB(chap3) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "passing primitive variables KB(chap3)" Watch "passing primitive variables KB(chap3)" New topic
Author

passing primitive variables KB(chap3)

Syed Naimathullah
Greenhorn

Joined: Feb 18, 2007
Posts: 17
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

Joined: Sep 11, 2006
Posts: 959

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


SCJP 5.0, SCWCD 1.4, SCBCD 1.3, SCDJWS 1.4
My Blog
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Please use Code Tags when posting code. Thanks!


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: passing primitive variables KB(chap3)