If you implement an interface compiler asks you to provide implementation of those methods. But in case of calling overridden clone() method how compiler come to know that a particular interface is not mentioned (here in this case Cloneable
) in class declaration. How compiler does this mapping to tell user that CloneNotSupported ? Is it has something to do with late-binding?
I think JVM has information about each class in method area like what are classes it is extending and what are interfaces it is implementing. So calling clone() method will check into those stored metadata about the class and finds out that Cloneable
is not in that list of interfaces ? Is this somewhere close to correct answer ?