public class CreatingObjectusingCloneMethodShallowCloning implements Cloneable{
String name;
int rollno;
String housename;
//Defining the clone method
protected Object clone() throws CloneNotSupportedException {
return super.clone();
}
public static void main(String args[]) throws CloneNotSupportedException {
CreatingObjectusingCloneMethodShallowCloning obj=new CreatingObjectusingCloneMethodShallowCloning();
CreatingObjectusingCloneMethodShallowCloning obj2= (CreatingObjectusingCloneMethodShallowCloning) obj.clone();
obj.housename="HouseName-1";
obj2.housename="HouseName-2";
System.out.println(obj.housename);
}
}
I have assigned a value to housename using object - obj. In the next step I changed the value using obj2. If I print it using obj should it reflect the value that I assigned second?