Hai All,
I have to set of Programs, Both deals with Object, One is with Predefined Object and another one is User Defined Object.
Program #1
Program #2
In Prg #1 object value doesnt changed
In Prg #2 Change the value
I have to set of Programs, Both deals with Object, One is with Predefined Object and another one is User Defined Object.
Program #1
Code:
class MyPass
{
Integer i=new Integer(100);
public void pass(){
System.out.println(i);
go(i);
System.out.println(i);
}
public void go(Integer x){
System.out.println(x);
x=200;
System.out.println(x);
}
public static void main(String arg[]){
MyPass mp=new MyPass();
mp.pass();
}
}
OUTPUT:
100
100
200
100
Program #2
Code:
class Refer
{
String name;
}
class PassByReference
{
void calling()
{
Refer r=new Refer();
r.name="abc";
System.out.println("Before"+r.name);
called(r);
System.out.println("After"+r.name);
}
void called(Refer s)
{
s.name="xyz";
System.out.println("Inside"+s.name);
}
public static void main(String args[])
{
PassByReference p=new PassByReference();
p.calling();
}
}
OUTPUT:
Beforeabc
Insidexyz
Afterxyz
In Prg #2 Change the value
Comment