Get Job-ready: Java Course with 45+ Real-time Projects! - Learn Java
Program 1
class TestCall
{
int n=100; // Instance variable
void show( TestCall temp) // call by value
{
temp.n=temp.n+10;
}
void display(int ar[])
{
ar[0]=100;
ar[1]=200;
}
}
class TestCallbyValue
{
public static void main(String args[])
{
TestCall T1=new TestCall();
// System.out.println("Before Call Value is :" + T1.n);
// T1.show(T1);
// System.out.println("Before call: " +T1.n);
int a[]={1,2,3,4,5,6,7,8};
System.out.println("Before Call Value is :");
for(int i=0;i<a.length;i++)
System.out.println(a[i]);
T1.display(a);
System.out.println("After Call Value is :");
for(int i=0;i<a.length;i++)
System.out.println(a[i]);
}
}