Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

passing primitive variables KB(chap3)

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);

}
}
 
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please use Code Tags when posting code. Thanks!
 
reply
    Bookmark Topic Watch Topic
  • New Topic