Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

please explain

 
vineet walia
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • 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]
 
Himanshu Kansal
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • 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: 138
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
 
Mo Jay
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic