Giffy Geraldo wrote:Here I have a question - which clone() will set the value of X that is being inherited by Bar from Foo. If the clone() method as being used with super() is doing that- isn't it doing a deep copy?
I am not sure I get your question, but I will give it a shot:
When you clone an object using the default clone() implementation from Object, which is what you ultimately are doing when you simply use super.clone(), you get a whole new object, but any objects which are bound to instance variables are not cloned.
For example, let's say you have an object of class A which has a x reference variable of type Integer. If you clone an object of class A, you get a new instance of class A, but its x reference variable will point to the same object as the x reference variable in the object which you cloned from. Maybe Mike can correct me (or you can tell me what I didn't understand from your question.)