Monday, December 5, 2016

Write a JAVA program for call by Reference.

 Aim: Write a JAVA program for  call by Reference. 

Program:

class Operation2
{  
 int data=50;  
  
 void change(Operation2 op)
 {  
 op.data=op.data+100;//changes will be in the instance variable  
 }  
     
    
 public static void main(String args[])
 {  
   Operation2 op=new Operation2();  
  
   System.out.println("before change "+op.data);  
   op.change(op);//passing object  
   System.out.println("after change "+op.data);  
  
 }  
}  

Output:


Labels:

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home