
5.12 Class Objects and Methods
13. int x=10;int y=100;
14. CallByVal val = new CallByVal();
15. val.SwapData(x,y);
16. System.out.println(“Inside main :return from SwapData, “);
17. System.out.println(“x:” + x + “y:”+y);}
18. }
Output: Inside SwapDataBefore Swap……… x:10y:100
Inside SwapData, After Swap ………. x:100y:10
Inside main on return from SwapData, x:10y:100
Line No. 15: we have passed data by call by value. Line Nos. 8 and 9 show that
values inside Swapdata have indeed been swapped. These are local
changes.
Line Nos. 16 and 17: show that values of x and y remain unchanged after return from
SwapData. This is characteristic of Call by ...