Main Method:
package pkg2c;
public class Main {
public static void main(String[] args)
{
Test obj1 = new Test();
System.out.println("Obj1.a: "+obj1.a);
System.out.println("Obj1.b: "+obj1.b);
System.out.println("Obj1.a: "+obj1.c);
Test obj2 = new Test();
obj2.update(obj1);
System.out.println("Obj1.a: "+obj1.a);
System.out.println("Obj1.b: "+obj1.b);
System.out.println("Obj1.a: "+obj1.c);
obj2=obj1;
obj2.update(obj1);
System.out.println("Obj2.a: "+obj2.a);
System.out.println("Obj2.b: "+obj2.b);
System.out.println("Obj2.a: "+obj2.c);
}
}
Output
Obj1.a:1
Obj1.b:2
Obj1.a:0
Obj1.a:2
Obj1.b:2
Obj1.a:1
Obj1.a:3
Obj1.b:3
Obj1.a:2
Add your comment