• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

please explain

 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am new in programing
anybody explain difference between call by value and call by reference with example ?
please also explain this program





[HENRY: Added code tags]
 
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

please post the code in proper tags.

Also, the code is not complete. Value class is missing

Regards
 
vineet walia
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Himanshu Kansal wrote:Hello,

please post the code in proper tags.

Also, the code is not complete. Value class is missing

Regards


its working and its output is 15 0
20
 
Himanshu Kansal
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Once you edited to put the Class Value's definition, you could have put in the CODE tags too.
 
Himanshu Kansal
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is a line to clear all misunderstandings - Java is strictly Pass-by-Value.

If at some point you feel that a pass by reference has occured as in your code at second(v,i), you actually are passing the reference itself as a value. Hence any changes made to the reference are reflected in the actual arg.

I hope that you are clear that when we say, "a" is only a reference that points to the object. Therefore, when you pass this "a" to a method, you actually pass a reference pointing to that object; which in turn is a pass by value because the reference is COPIED in the formal argument

Regards
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also vineet walia , you need to quote your sources and say where you got this code from. This is one of the requirements when posting any piece of code here.

As of the output of the program, it is strait forward and I think that the guys (Himanshu) before me have done a good job describing the difference (if there is any) between pass-by-value and pass-by-reference.
 
reply
    Bookmark Topic Watch Topic
  • New Topic