Write a program in java to demonstrate call by reference?

class CallByReference

{

                int data=50;

                void change(CallByReference call)

                {

                                call.data=call.data+100; //Changes will be in the intstance variable

                }

                public static void main(String arg[])

                {

                                CallByReference call=new CallByReference();

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

                                call.change(call);               //Passing Object

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

                }

}

Call By Reference.PNG

, , , , ,

Leave a Reply