Program to demonstrates Call by Value

/* Program to demonstrates Call by Value  */

class Sample
{ int c,d;
     
   
    void cal(int c, int d)
    {  
       
        c=c+2;
        d=d-2;
   
    }
}

class CallByValue
{
    public static void main(String args[])
    {
        Sample s=new Sample();
        int p=20,q=10;

        System.out.println(" p and q Before call :"+p+", "+q);
       
        s.cal(p,q);

        System.out.println(" p and q After call  :"+p+", "+q);
    }
}

0 comments:

Post a Comment

 
 
 
 


Copyright © 2012 http://codeprecisely.blogspot.com. All rights reserved |Term of Use and Policies|