Regarding Clone hierarchy #40
-
I am a bit confused over why the following code works: Assuming main calls var a = new A().clone(); class A extends B implements Cloneable { abstract class B{ Here, class B does not implement Cloneable, yet it works. I am a bit confused over why. Is it enough that either just A or just B has implements Cloneable? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The abstract class B implicitly extends java.lang.Object. It overrides the clone() methods of Object. Any classes can override the clone() method without the need to implement the Cloneable interface, which has an empty body. Hope it clarifies. |
Beta Was this translation helpful? Give feedback.
The abstract class B implicitly extends java.lang.Object. It overrides the clone() methods of Object. Any classes can override the clone() method without the need to implement the Cloneable interface, which has an empty body. Hope it clarifies.