Write a program in java to demonstrate call by value?

class CallByValue

{

                int data=50;

                void change(int data)

                {

                                data=data+100; //Changes will be the local variable only

                }

                public static void main(String arg[])

                {

                                CallByValue call=new CallByValue();

                                System.out.println("Before Change "+call.data);

                                call.change(500);

                                System.out.println("After Change "+call.data);

                }

}

Call By Value.PNG

, , , , ,

Leave a Reply