class Human {
int age;
long salary;
}
public class ShallowCopyExe {
public static void main(String args[]) {
Human h1 = new Human();
h1.age = 20;
h1.salary = 1000;
System.out.println("h1 age: "+h1.age+", h1 salary: "+h1.salary);
Human h2 = h1;
h2.salary = 1200;
System.out.println("h1 age: "+h1.age+", h1 salary: "+h1.salary);
System.out.println("h2 age: "+h2.age+", h2 salary: "+h2.salary);
}
}
Output:
h1 age: 20, h1 salary: 1000
h1 age: 20, h1 salary: 1200
h2 age: 20, h2 salary: 1200
int age;
long salary;
}
public class ShallowCopyExe {
public static void main(String args[]) {
Human h1 = new Human();
h1.age = 20;
h1.salary = 1000;
System.out.println("h1 age: "+h1.age+", h1 salary: "+h1.salary);
Human h2 = h1;
h2.salary = 1200;
System.out.println("h1 age: "+h1.age+", h1 salary: "+h1.salary);
System.out.println("h2 age: "+h2.age+", h2 salary: "+h2.salary);
}
}
Output:
h1 age: 20, h1 salary: 1000
h1 age: 20, h1 salary: 1200
h2 age: 20, h2 salary: 1200
No comments:
Post a Comment