File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

passing primitive variables KB(chap3)

Syed Naimathullah

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);
System.out.println("After modify() d.height="+d.height);
void modify(Dimension dim)

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.

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

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
I agree. Here's the link:
subject: passing primitive variables KB(chap3)
It's not a secret anymore!