Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes 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 ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Help with code

Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I dont understand this how does orig turn into to arg can somebody please explain

Ranch Hand
Posts: 529
Eclipse IDE MySQL Database Tomcat Server Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here x is reference variable of an instance of class XCopy, which holds the reference of an object of class XCopy.
In below code your calling instance method go(int arg) and passing orig as int parameter whose value is 42 (int).
Below int go(int arg) is an instance method whose return type is int means method must return int value.
Here arg is local variable of method go, value of variable orig is copied in local variable arg of method go().
(Note: No operation on orig variable so value of orig will be same as it is i.e. 42)
Now arg = 42.
Here arg = arg * 2; means arg = 42 * 2 so arg becomes 84. and
returns arg variable's value i.e. 84 to the point where it was called from so control goes to here
and assigns 84 value in variable y so now y = 84. Then you printed it
prints value of orig which is 42 and value of y i.e. 84 which you got by
Output: 4284
Poop goes in a willow feeder. Wipe with this tiny ad:
Garden Master Course kickstarter
    Bookmark Topic Watch Topic
  • New Topic